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 452

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

  • Verified answer
    Albert_ Profile Picture
    452 on at
    RE: change state and statusreason of salesorder ( order entity ) via JavaScript

    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.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: change state and statusreason of salesorder ( order entity ) via JavaScript

    Hi Albert,

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

    Hope this helps.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,914 on at
    RE: change state and statusreason of salesorder ( order entity ) via JavaScript

    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
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: change state and statusreason of salesorder ( order entity ) via JavaScript

    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.

  • Albert_ Profile Picture
    452 on at
    RE: change state and statusreason of salesorder ( order entity ) via JavaScript

    I use crm 2011 sir

  • Suggested answer
    Drew Poggemann Profile Picture
    4 on at
    RE: change state and statusreason of salesorder ( order entity ) via JavaScript

    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!

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans