locked
Lead / Qualify - can it be cancelled? RRS feed

  • Question

  • I am >   CRM 2011 RU13 On-Premise

    I'm trying to cancel the Lead / Qualify step but am receiving an error. All code seems to work

    properly except the "ExecutionObj.getEventArgs().preventDefault();" statement that will cancel this step.

    Code & error follow.

    Thanks in advance for your assistance

    function Form_onsave(ExecutionObj)

    {

    var eventmode=ExecutionObj.getEventArgs().getSaveMode();

     if (ocbuItem == "Residential Sales")

        {

          if (eventmode == 1 || eventmode == 2)

                     //  save = 1 ,  save & close = 2

            {

               if(Xrm.Page.getAttribute("new_resleaddetail").getValue() == null)

                 {

                    var msg = "Reminder: Res Lead Detail field is required";

                    alert(msg);

                    // Give the control focus.

                    Xrm.Page.ui.controls.get("new_resleaddetail").setFocus(true);

                    ExecutionObj.getEventArgs().preventDefault();

                 }     

            }

          if (eventmode == 16)

                 // 16 = qualify option chosen from the convert lead dialog box

            {

              var msg = "You chose QUALIFY, this is outside the scope of your usage.  Please select DISQUALIFY.";

              alert(msg);

              // Cancel the qualify operation.

                  ExecutionObj.getEventArgs().preventDefault();

            }

        }  // end residential sales

    } // end onsave

    Microsoft Dynamics CRM Error Report Contents

    <CrmScriptErrorReport>

      <ReportVersion>1.0</ReportVersion>

      <ScriptErrorDetails>

       <Message>Unable to get value of the property 'parentNode': object is null or undefined</Message>

       <Line>1</Line>

       <URL>/main.aspx?etc=4&extraqs=%3f_gridType%3d4%26etc%3d4%26id%3d%257b6FFB77C6-F50F-E311-A0FB-005056814586%257d%26pagemode%3diframe%26preloadcache%3d1379093638422%26rskey%3d908545450&pagetype=entityrecord</URL>

       <PageURL>/main.aspx?etc=4&extraqs=%3f_gridType%3d4%26etc%3d4%26id%3d%257b6FFB77C6-F50F-E311-A0FB-005056814586%257d%26pagemode%3diframe%26preloadcache%3d1379093638422%26rskey%3d908545450&pagetype=entityrecord</PageURL>

       <Function></Function>

       <CallStack>

       </CallStack>

      </ScriptErrorDetails>

      <ClientInformation>

       <BrowserUserAgent>Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.2; .NET4.0E; MS-RTC EA 2)</BrowserUserAgent>

       <BrowserLanguage>en-us</BrowserLanguage>

       <SystemLanguage>en-us</SystemLanguage>

       <UserLanguage>en-us</UserLanguage>

       <ScreenResolution>1680x1050</ScreenResolution>

       <ClientName>Web</ClientName>

       <ClientTime>2013-09-13T13:34:17</ClientTime>

      </ClientInformation>

      <ServerInformation>

        <OrgLanguage>1033</OrgLanguage>

        <OrgCulture>1033</OrgCulture>

        <UserLanguage>1033</UserLanguage>

        <UserCulture>1033</UserCulture>

        <OrgID>{D0B813F1-3BD1-E111-8F27-005056814586}</OrgID>

        <UserID>{EB773814-3DD1-E111-8F27-005056814586}</UserID>

        <CRMVersion>5.0.9690.3448</CRMVersion>

      </ServerInformation>

    </CrmScriptErrorReport>



    • Edited by Jim4177 Tuesday, September 17, 2013 4:38 PM
    Friday, September 13, 2013 6:07 PM

All replies

  • Forum,

    Does anyone have any thoughts, ideas or workarounds to this issue?

    Tuesday, September 17, 2013 12:27 PM
  • Try

    The pass execution context as first parameter checkbox is very important to this process. Without it, it will not work.

    OR

    ExecutionObj.getEventArgs().IsDefaultPrevented();

    OR

    event.returnValue = false;

    return false;


    Regards Faisal



    • Edited by Faisal Fiaz Tuesday, September 17, 2013 12:59 PM
    Tuesday, September 17, 2013 12:58 PM
  • You defined the a variable 'eventmode' - all lowercase and then try and reference it as 'eventMode' - uppercase 'M' - JavaScript is case sensitive

    This basic script works to prevent a qualify:


    function Form_onsave(ExecutionObj) {
        var eventMode = ExecutionObj.getEventArgs().getSaveMode();
        if (eventMode == 16) {
            var msg = "You chose QUALIFY, this is outside the scope of your usage.  Please select DISQUALIFY.";
            alert(msg);
            ExecutionObj.getEventArgs().preventDefault();
        }
    }
    


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, September 17, 2013 1:05 PM
    Moderator
  • Jason,

    I must apologize,  in my attempt to minimize code down to the problem area I 
    inadvertently left in old code.  I have corrercted my code snippet.

    Tuesday, September 17, 2013 3:04 PM
  • Has anyone answered this? I'm having the same problem for, apparently, the same reason.

    Thanks,

    -Al

    Friday, January 30, 2015 4:36 PM
  • Hi,

    You wrote:

    if (ocbuItem == "Residential Sales")
    but i dont see, where you define "ocbuItem". Are you sure, that it is not null?
    Monday, February 2, 2015 9:55 AM
  • Al,

    I started the original post ...........  the following code does work...
    Hope this helps.

    function Form_onsave(ExecutionObj)
    //function Form_onsave()

    {

    //debugger;

    var eventmode=ExecutionObj.getEventArgs().getSaveMode();
    //       alert('event mode is '+ eventmode);


    //Build an array with Comporium Business Unit values  >>>>
      var arrcbu = new Array;
      arrcbu = Xrm.Page.getAttribute("new_comporiumbusinessunitid").getValue();
      if (arrcbu != null)
        {
           var ocbuItem = arrcbu[0].name;
    //       alert('Comporium bus unit name = '+ ocbuItem);
        }

    //  -------------------------------------------------------------------------------------
     
    //>>>>>>>>>>>>>>>>> RESIDENTIAL SALES <<<<<<<<<<<<<
    // When BU = Residential Sales and EVENT.mode = QUALIFY
    // we want to CANCEL this operation.  Because its 'residential',
    // These users will never qualify and convert a lead. 

      if (ocbuItem == "Residential Sales")

        {

          if (eventmode == 1 || eventmode == 2)
    //      if (event.Mode == 1 || event.Mode == 2)
                     //  save = 1 ,  save & close = 2
            {
    //           if(crmForm.all.new_resleaddetail.DataValue == null)
               if(Xrm.Page.getAttribute("new_resleaddetail").getValue() == null)

                 {
                    var msg = "Reminder: Res Lead Detail field is required";
                    alert(msg);

                    // Give the control focus.
    //                crmForm.all.new_resleaddetail.SetFocus();
                    Xrm.Page.ui.controls.get("new_resleaddetail").setFocus(true);

    //                event.returnValue = false;
    //                return false;
                    ExecutionObj.getEventArgs().preventDefault();

                 }

    //           if(crmForm.all.new_resleadstatus.DataValue == null)
                 else if(Xrm.Page.getAttribute("new_resleadstatus").getValue() == null)

                          {
                             var msg = "Reminder: Res Lead Status field is required";
                             alert(msg);

                             // Give the control focus.
    //                         crmForm.all.new_resleadstatus.SetFocus();
                             Xrm.Page.ui.controls.get("new_resleadstatus").setFocus(true);

    //                         event.returnValue = false;
    //                         return false;
                             ExecutionObj.getEventArgs().preventDefault();

                          }

    //           if(crmForm.all.new_spiffeligible.DataValue == null)
                  else if(Xrm.Page.getAttribute("new_spiffeligible").getValue() == null)

                           {
                               var msg = "Reminder: SPIFF Eligible field is required";
                               alert(msg);

                               // Give the control focus.
    //                           crmForm.all.new_spiffeligible.SetFocus();
                               Xrm.Page.ui.controls.get("new_spiffeligible").setFocus(true);

    //                           event.returnValue = false;
    //                           return false;
                               ExecutionObj.getEventArgs().preventDefault();

                           }

            }  // end event mode 1 & 2

          if (eventmode == 16)
    //      if (event.Mode == 16)
                 // 16 = qualify option chosen from the convert lead dialog box
            {
                var msg = "You chose QUALIFY, this is outside the scope of your usage.  Please select DISQUALIFY.";
                alert(msg);

              // Cancel the qualify operation.

    //              event.returnValue = false;
    //              return false;

                ExecutionObj.getEventArgs().preventDefault();

               
            } // end event mode = 16

        }  // end residential sales

    } // end onsave

    Monday, February 2, 2015 12:29 PM