I'm trying to build a plugin that does some operations on a salesorder. I also have to set a order as fulfilled. I found on the SDK documentation an extract that must be used to fulfill the order in the right way
var request = new FulfillSalesOrderRequest
{
OrderClose = new OrderClose
{
SalesOrderId = new EntityReference
{ LogicalName = orderEntityName, Id = orderId }
},
Status = new OptionSetValue(newStatus)
};
The problem is that the code cannot be compiled because MVS says "The type or namespace name 'OrderClose' could not be found (are you missing a using directive or an assembly reference?)". RightClicking on "new OrderClose" (OrderClose is underlined in red) I cannot see the Resolve section in the menu. I have also tried this way:
var request = new FulfillSalesOrderRequest();
request.OrderClose = new OrderClose();
request.OrderClose.LogicalName = orderEntityName;
request.OrderClose.Id = orderId;
request.Status = new OptionSetValue(newStatus);
How can I make the code compiling (and hopefully working)?
Since OrderClose
is not a class, but the name of a Property, you cannot create it using new
.
As the property is of type Entity
, you need to create an instance of Entity
like this:
request.OrderClose = new Entity();
OrderClose is in the Assembly "Microsoft.Crm.Sdk.Proxy" (in Microsoft.Crm.Sdk.Proxy.dll)
Have you added Microsoft.Crm.Sdk.Proxy.dll as a reference? Not just
using Microsoft.Crm.Sdk.Messages;
but actually going over to the solution explorer pane and right clicking References > Add Reference and choosing Microsoft.Crm.Sdk.Proxy.dll.
Edit: Right clicking on something red-squigglied and picking "Resolve" won't work unless the correct assembly is referenced.
It sounds like the sample code assumes you have generated the early-bound code for your organization. If you included the early-bound code in your project, this reference would resolve. See this link:
https://msdn.microsoft.com/en-us/library/gg327844.aspx
The CrmSvcUtil.exe is part of the CRM SDK. Here is a template of how to use it:
CrmSvcUtil.exe /url:http://<serverName>/<organizationName>/XRMServices/2011/Organization.svc /out:<outputFilename>.cs /username:<username> /password:<password> /domain:<domainName> /namespace:<outputNamespace> /serviceContextName:<serviceContextName>
That is an early bound request, that's why you can't compile, if you aren't using the CrmScvUtil.
This is an example of a late bound request:
This namespace is needed.
using Microsoft.Xrm.Sdk.Messages;
And this is the code.
var request = new FulfillSalesOrderRequest();
request.OrderClose = new Entity("orderclose");
request.OrderClose["salesorderid"] = new EntityReference("salesorder", new Guid("YOURGUID"));
request.Status = new OptionSetValue(100001);
service.Execute(request);
100001
is the status code for Complete.
If you want to handle the response, use a variable to receive the answer.
来源:https://stackoverflow.com/questions/28730095/unable-to-compile-code-when-using-orderclose-class