Tuesday 26 July 2016

How to Fulfill an Order by C# code in Microsoft Dynamics CRM

Hi All. Sometimes we come across certain situations where we need to Fulfill an Order by our code of Plugin or Workflow. Here I am going to explain you step by step how to Fulfill an Order via C# code in Microsoft Dynamics CRM.

Step1:

Get the GUID of the Order record which you want to fulfill. Lets say "orderGuid".

Step2:

Get the optionset value of the "Status" which fulfills the Order. In my case it is 100001(Fulfill).

Step3:

Add the reference "Microsoft.Crm.Sdk.Messages" to your code.
"using Microsoft.Crm.Sdk.Messages;"

Step4:

Add the below code:

FulfillSalesOrderRequest req = new FulfillSalesOrderRequest();
req.OrderClose = new Entity("orderclose");
req.OrderClose["salesorderid"] = new EntityReference("salesorder", orderGuid);
req.Status = new OptionSetValue(100001); //Fulfill = 100001
localContext.Trace("before executing");
FulfillSalesOrderResponse resp = (FulfillSalesOrderResponse)localContext.OrganizationService.Execute(req);
localContext.Trace("after executing");

Explaination:

In CRM, we have an entity called as "orderclose". When an order gets fulfilled, an entry is created in this entity with the reference of the fulfilled order. Here, we have achieved the same thing via c# code.

5 comments:

  1. Thanks for this nice article.. Resolved my problem..

    ReplyDelete
    Replies
    1. Awesome article...
      keep writing good articles like this.

      Delete
  2. I like what you guys are up too. Such smart work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my site 🙂search engine optimization services company

    ReplyDelete