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)

change state and statusreason of salesorder ( order entity ) via JavaScript

(0) ShareShare
ReportReport
Posted on by 458

Hi all experts.
We all know that Order states are :

0-Active
1-Submiited

2-Canceled

3-Fulfilled

4-Invoiced

I wanna go from Submitted( in progress statusreason ) to Fullfield ( Partial statusreson) with soap.
Here is the code and function :

function changeStatusCodeToPartial()  { 
   XrmServiceToolkit.Soap.SetState("salesorder", Xrm.Page.data.entity.getId(), 3, 100002, false);
  Xrm.Page.data.refresh(true).then(null, null);
 }

But does not work.
I can go from Active ( prepared statusreason) to Submitted ( in-progress via below code ) :
function changeStatusCodeToSubmitted() { 
   XrmServiceToolkit.Soap.SetState("salesorder", Xrm.Page.data.entity.getId(),1, 3, false);
   Xrm.Page.data.refresh(true).then(null, null);

}

How can it be possible?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Drew Poggemann Profile Picture
    4 on at

    Hi Albert,

    You will need to set the state transitions for the status reason code or this will fail.  See the following article for details on how to set the transitions.

    www.preact.co.uk/.../how-to-set-dynamics-crm-status-reason-transitions

    Hope this helps!

  • Albert_ Profile Picture
    458 on at

    I use crm 2011 sir

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Insteadd of setting the state directly, try using the FulfillSalesOrderRequest message-

    docs.microsoft.com/.../gg307979(v=crm.5)

    mileyja.blogspot.com/.../full-sales-order-in-microsoft-dynamics.html

    Hope this helps.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Hi,

    Do you have the error log when you changed it? In my experience when I'm work at Incident Entity. I need to change the statecode to Active first because CRM operation denied me to change directly to another statecode.

    Try to put debugger when you do SetState. From that it will be more clearer to do something.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Albert,

    See: mileyja.blogspot.com/.../set-status-or-state-of-record-using.html

    Hope this helps.

  • Verified answer
    Albert_ Profile Picture
    458 on at

    Hi there All, THank u for your support,

    It suppose that for  Canceled and Fulfilled we should different service names !

    So for Canceled I did this :

    ...........................................................................................................................................................................

                var requestMain = ""

                  requestMain += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";

                  requestMain += "  <s:Body>";

                  requestMain += "    <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";

                  requestMain += "      <request i:type=\"b:CancelSalesOrderRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\" xmlns:b=\"schemas.microsoft.com/.../Contracts\">";

                  requestMain += "        <a:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">";

                  requestMain += "          <a:KeyValuePairOfstringanyType>";

                  requestMain += "            <c:key>OrderClose</c:key>";

                  requestMain += "            <c:value i:type=\"a:Entity\">";

                  requestMain += "              <a:Attributes>";

                  requestMain += "                <a:KeyValuePairOfstringanyType>";

                  requestMain += "                  <c:key>salesorderid</c:key>";

                  requestMain += "                  <c:value i:type=\"a:EntityReference\">";

                  requestMain += "                    <a:Id>" +recordGuid+ "</a:Id>";

                  requestMain += "                    <a:LogicalName>salesorder</a:LogicalName>";

                  requestMain += "                    <a:Name i:nil=\"true\" />";

                  requestMain += "                  </c:value>";

                  requestMain += "                </a:KeyValuePairOfstringanyType>";

                  requestMain += "                <a:KeyValuePairOfstringanyType>";

                  requestMain += "                  <c:key>subject</c:key>";

                  requestMain += "                  <c:value i:type=\"d:string\" xmlns:d=\"www.w3.org/.../XMLSchema\">Sales Order Cancelled - No Money</c:value>";

                  requestMain += "                </a:KeyValuePairOfstringanyType>";

                  requestMain += "              </a:Attributes>";

                  requestMain += "              <a:EntityState i:nil=\"true\" />";

                  requestMain += "              <a:FormattedValues />";

                  requestMain += "              <a:Id>00000000-0000-0000-0000-000000000000</a:Id>";

                  requestMain += "              <a:LogicalName>orderclose</a:LogicalName>";

                  requestMain += "              <a:RelatedEntities />";

                  requestMain += "            </c:value>";

                  requestMain += "          </a:KeyValuePairOfstringanyType>";

                  requestMain += "          <a:KeyValuePairOfstringanyType>";

                  requestMain += "            <c:key>Status</c:key>";

                  requestMain += "            <c:value i:type=\"a:OptionSetValue\">";

                  requestMain += "              <a:Value>" +statusCode+"</a:Value>";

                  requestMain += "            </c:value>";

                  requestMain += "          </a:KeyValuePairOfstringanyType>";

                  requestMain += "        </a:Parameters>";

                  requestMain += "        <a:RequestId i:nil=\"true\" />";

                  requestMain += "        <a:RequestName>CancelSalesOrder</a:RequestName>";

                  requestMain += "      </request>";

                  requestMain += "    </Execute>";

                  requestMain += "  </s:Body>";

                  requestMain += "</s:Envelope>";

                  var req = new XMLHttpRequest();

                  req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true);

                  // Responses will return XML. It isn't possible to return JSON.

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

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

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

                  var successCallback = null;

                  var errorCallback = null;

                  req.send(requestMain);

    ...........................................................................................................................................................................

    And for Fulfilled I do this :

    ...........................................................................................................................................................................

                     var requestMain = ""

                  requestMain += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";

                  requestMain += "  <s:Body>";

                  requestMain += "    <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";

                  requestMain += "      <request i:type=\"b:FulfillSalesOrderRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\" xmlns:b=\"schemas.microsoft.com/.../Contracts\">";

                  requestMain += "        <a:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">";

                  requestMain += "          <a:KeyValuePairOfstringanyType>";

                  requestMain += "            <c:key>OrderClose</c:key>";

                  requestMain += "            <c:value i:type=\"a:Entity\">";

                  requestMain += "              <a:Attributes>";

                  requestMain += "                <a:KeyValuePairOfstringanyType>";

                  requestMain += "                  <c:key>salesorderid</c:key>";

                  requestMain += "                  <c:value i:type=\"a:EntityReference\">";

                  requestMain += "                    <a:Id>" +recordGuid+ "</a:Id>";

                  requestMain += "                    <a:LogicalName>salesorder</a:LogicalName>";

                  requestMain += "                    <a:Name i:nil=\"true\" />";

                  requestMain += "                  </c:value>";

                  requestMain += "                </a:KeyValuePairOfstringanyType>";

                  requestMain += "                <a:KeyValuePairOfstringanyType>";

                  requestMain += "                  <c:key>subject</c:key>";

                  requestMain += "                  <c:value i:type=\"d:string\" xmlns:d=\"www.w3.org/.../XMLSchema\">Sales Order Closed</c:value>";

                  requestMain += "                </a:KeyValuePairOfstringanyType>";

                  requestMain += "              </a:Attributes>";

                  requestMain += "              <a:EntityState i:nil=\"true\" />";

                  requestMain += "              <a:FormattedValues />";

                  requestMain += "              <a:Id>00000000-0000-0000-0000-000000000000</a:Id>";

                  requestMain += "              <a:LogicalName>orderclose</a:LogicalName>";

                  requestMain += "              <a:RelatedEntities />";

                  requestMain += "            </c:value>";

                  requestMain += "          </a:KeyValuePairOfstringanyType>";

                  requestMain += "          <a:KeyValuePairOfstringanyType>";

                  requestMain += "            <c:key>Status</c:key>";

                  requestMain += "            <c:value i:type=\"a:OptionSetValue\">";

                  requestMain += "              <a:Value>"+statusCode+"</a:Value>";

                  requestMain += "            </c:value>";

                  requestMain += "          </a:KeyValuePairOfstringanyType>";

                  requestMain += "        </a:Parameters>";

                  requestMain += "        <a:RequestId i:nil=\"true\" />";

                  requestMain += "        <a:RequestName>FulfillSalesOrder</a:RequestName>";

                  requestMain += "      </request>";

                  requestMain += "    </Execute>";

                  requestMain += "  </s:Body>";

                  requestMain += "</s:Envelope>";

                  var req = new XMLHttpRequest();

                  req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true);

                  // Responses will return XML. It isn't possible to return JSON.

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

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

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

                  var successCallback = null;

                  var errorCallback = null;

                   req.send(requestMain);

    ...........................................................................................................................................................................

    Just replace statusCode and recordGuid with your own.

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