web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Changing the lead status into disqualified via SOAP request and some JS

(0) ShareShare
ReportReport
Posted on by

Hi all,

We are writing a customized solution to achieve certain functionality. We have stumbled across peculiar problem, and we weren't able to found a direct and clean solution / explanation online. 

We are stuck somewhere around this piece of code:

<a:KeyValuePairOfstringanyType>");

request.push(" <c:key>Status</c:key>");
request.push(" <c:value i:type=\"a:OptionSetValue\">");
request.push(" <a:Value>3</a:Value>"); 
request.push(" </c:value>");

When implemented this function will set the lead status as 'Qualified Opportunity' but we want for function to set the different value.

How do we achieve that? And where is the list of Values that the function picks up? 

Is this a good direction: http://www.xrmcoaches.com/2012/01/changing-the-lead-qualification-status-values/ ; look at chart at the bottom. 

If it is, how do we set it up to set the lead status as lets say: 'Cannot Contact'

Thanks! 

*This post is locked for comments

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Open default solution -> Entities -> Lead -> Fields -> statuscode -> open that field. Choose disqualified in state code field and you will see all available values of status code for disqualified state code.

  • Community Member Profile Picture
    on at

    Hi Andrii,

    Thanks for the help. Your answer did help me figure out what value to call but it didnt resolve my problem.

    Interestingly, the value I'm calling for is 100,000,006 and it simply doesn't work when I enter it. 

    Actually the entire code does not work except when the value is 3. 

    Any ideas why? 

    Let me give some context, I'm trying to recreate Jason Lattimer's solution into creating a 'Qualify button' button that will create account and contact without creating an opportunity. (as seen here: http://jlattimer.blogspot.cz/2014/09/qualify-leads-without-creating.html; Thanks Jason for the solution and know how). 

    Now, his solution qualifies the lead as it should, but it sets the status reason as: Qualified Opportunity. I guess this is piece of code is saying that: 

     <a:KeyValuePairOfstringanyType>");

        request.push("             <c:key>Status</c:key>");

        request.push("             <c:value i:type=\"a:OptionSetValue\">");

        request.push("               <a:Value>3</a:Value>"); //Qualified

        request.push("             </c:value>");

    Now I wanted the same functionality and everything, but just to change the status code 'Not Qualified', i.e. to call the value 100,000,006 - and I cant make it work. :) 

    Thanks for the help! 

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Please provide full code you use. Not only part you provided already.

  • Community Member Profile Picture
    on at

    Here it is:

    (All Credits go to Jason Lattimer - jlattimer.blogspot.cz/.../qualify-leads-without-creating.html)

    function QualifyLead() {

       var request = [];

       request.push(" <s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">");

       request.push("   <s:Body>");

       request.push("     <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">");

       request.push("       <request i:type=\"b:QualifyLeadRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\" xmlns:b=\"schemas.microsoft.com/.../Contracts\">");

       request.push("         <a:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">");

       request.push("           <a:KeyValuePairOfstringanyType>");

       request.push("             <c:key>LeadId</c:key>");

       request.push("             <c:value i:type=\"a:EntityReference\">");

       request.push("               <a:Id>" + Xrm.Page.data.entity.getId() + "</a:Id>");

       request.push("               <a:LogicalName>lead</a:LogicalName>");

       request.push("               <a:Name i:nil=\"true\" />");

       request.push("             </c:value>");

       request.push("           </a:KeyValuePairOfstringanyType>");

       request.push("           <a:KeyValuePairOfstringanyType>");

       request.push("             <c:key>CreateAccount</c:key>");

       request.push("             <c:value i:type=\"d:boolean\" xmlns:d=\"www.w3.org/.../XMLSchema\">true</c:value>");

       request.push("           </a:KeyValuePairOfstringanyType>");

       request.push("           <a:KeyValuePairOfstringanyType>");

       request.push("             <c:key>CreateContact</c:key>");

       request.push("             <c:value i:type=\"d:boolean\" xmlns:d=\"www.w3.org/.../XMLSchema\">true</c:value>");

       request.push("           </a:KeyValuePairOfstringanyType>");

       request.push("           <a:KeyValuePairOfstringanyType>");

       request.push("             <c:key>CreateOpportunity</c:key>");

       request.push("             <c:value i:type=\"d:boolean\" xmlns:d=\"www.w3.org/.../XMLSchema\">false</c:value>");

       request.push("           </a:KeyValuePairOfstringanyType>");

       request.push("           <a:KeyValuePairOfstringanyType>");

       request.push("             <c:key>Status</c:key>");

       request.push("             <c:value i:type=\"a:OptionSetValue\">");

       request.push("               <a:Value>3</a:Value>"); //Qualified

       request.push("             </c:value>");

       request.push("           </a:KeyValuePairOfstringanyType>");

       request.push("         </a:Parameters>");

       request.push("         <a:RequestId i:nil=\"true\" />");

       request.push("         <a:RequestName>QualifyLead</a:RequestName>");

       request.push("       </request>");

       request.push("     </Execute>");

       request.push("   </s:Body>");

       request.push(" </s:Envelope>");

       var serverUrl = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web";

       var req = new XMLHttpRequest();

       req.open("POST", serverUrl, false);

       req.setRequestHeader("Accept", "application/xml, text/xml, */*");

       req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

       req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute&quot;);

       req.onreadystatechange = function () {

           if (req.readyState == 4) {

               if (req.status == 200) {

                   var response = req.responseXML;

                   var id = $(response).children(":first").children(":first").children(":first").children(":first").children("a\\:Results").children("a\\:KeyValuePairOfstringanyType").children("c\\:value").children(":first").children("a\\:Id").text();

                   Xrm.Utility.openEntityForm("account", id);

               }

           }

       };

       req.send(request.join(""));

    }

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    This is the code written with Jason and I believe it works. I asked you to provide code that you modified for your need and that doesn't work.

  • Community Member Profile Picture
    on at

    Well actually I used the same thing.

    Just assumed that changing this bit would do the trick:

      request.push("             <c:key>Status</c:key>");

      request.push("             <c:value i:type=\"a:OptionSetValue\">");

      request.push("               <a:Value>100,000,006</a:Value>"); //Qualified

      request.push("             </c:value>");

    thats it. I tried with value 1, and 2, and nothing.

    Thats it.

    I didnt change anything else.

  • Community Member Profile Picture
    on at

    Full code:

    function QualifyLead() {

      var request = [];

      request.push(" <s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">");

      request.push("   <s:Body>");

      request.push("     <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">");

      request.push("       <request i:type=\"b:QualifyLeadRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\" xmlns:b=\"schemas.microsoft.com/.../Contracts\">");

      request.push("         <a:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">");

      request.push("           <a:KeyValuePairOfstringanyType>");

      request.push("             <c:key>LeadId</c:key>");

      request.push("             <c:value i:type=\"a:EntityReference\">");

      request.push("               <a:Id>" + Xrm.Page.data.entity.getId() + "</a:Id>");

      request.push("               <a:LogicalName>lead</a:LogicalName>");

      request.push("               <a:Name i:nil=\"true\" />");

      request.push("             </c:value>");

      request.push("           </a:KeyValuePairOfstringanyType>");

      request.push("           <a:KeyValuePairOfstringanyType>");

      request.push("             <c:key>CreateAccount</c:key>");

      request.push("             <c:value i:type=\"d:boolean\" xmlns:d=\"www.w3.org/.../XMLSchema\">true</c:value>");

      request.push("           </a:KeyValuePairOfstringanyType>");

      request.push("           <a:KeyValuePairOfstringanyType>");

      request.push("             <c:key>CreateContact</c:key>");

      request.push("             <c:value i:type=\"d:boolean\" xmlns:d=\"www.w3.org/.../XMLSchema\">true</c:value>");

      request.push("           </a:KeyValuePairOfstringanyType>");

      request.push("           <a:KeyValuePairOfstringanyType>");

      request.push("             <c:key>CreateOpportunity</c:key>");

      request.push("             <c:value i:type=\"d:boolean\" xmlns:d=\"www.w3.org/.../XMLSchema\">false</c:value>");

      request.push("           </a:KeyValuePairOfstringanyType>");

      request.push("           <a:KeyValuePairOfstringanyType>");

      request.push("             <c:key>Status</c:key>");

      request.push("             <c:value i:type=\"a:OptionSetValue\">");

      request.push("               <a:Value>100,000,006</a:Value>"); //Qualified

      request.push("             </c:value>");

      request.push("           </a:KeyValuePairOfstringanyType>");

      request.push("         </a:Parameters>");

      request.push("         <a:RequestId i:nil=\"true\" />");

      request.push("         <a:RequestName>QualifyLead</a:RequestName>");

      request.push("       </request>");

      request.push("     </Execute>");

      request.push("   </s:Body>");

      request.push(" </s:Envelope>");

      var serverUrl = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web";

      var req = new XMLHttpRequest();

      req.open("POST", serverUrl, false);

      req.setRequestHeader("Accept", "application/xml, text/xml, */*");

      req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

      req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");

      req.onreadystatechange = function () {

          if (req.readyState == 4) {

              if (req.status == 200) {

                  var response = req.responseXML;

                  var id = $(response).children(":first").children(":first").children(":first").children(":first").children("a\\:Results").children("a\\:KeyValuePairOfstringanyType").children("c\\:value").children(":first").children("a\\:Id").text();

                  Xrm.Utility.openEntityForm("account", id);

              }

          }

      };

      req.send(request.join(""));

    }

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Replace line

    request.push("               <a:Value>100,000,006</a:Value>");

    with line

    request.push("               <a:Value>100000006</a:Value>");

    The point is this value is in and commas are added just for visualization.

  • Community Member Profile Picture
    on at

    Is it that you have mixed up Status (statecode) with Status Reason (statuscode)?

  • Community Member Profile Picture
    on at

    Andrii, thanks, but this does not work. I already tried it, and tried with values 1 and 2.

    It only works with Value 3.

    Any other ideas? Maybe statecode should be changed as well somehow?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans