CancelSalesOrder Message (CrmService)
![]() |
[Applies to: Microsoft Dynamics CRM 4.0]
Find the latest SDK documentation: CRM 2015 SDK
| Works for all deployment types | Works online and offline |
Cancels a sales order.
The relevant classes are specified in the following table.
| Type | Class |
| Request | CancelSalesOrderRequest |
| Response | CancelSalesOrderResponse |
| Entity | salesorder |
Remarks
To use this message, pass an instance of the CancelSalesOrderRequest class as the request parameter in the Execute method.
To perform this action, the caller must have access rights on the salesorder entity instance. For a list of required privileges, see CancelSalesOrder Privileges.
Example
The following code example demonstrates how to cancel a sales order.
[C#]
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the order close activity object.
orderclose close = new orderclose();
// Set the properties of the order close object.
close.subject = "orderclose";
// Create a Lookup for the sales order being canceled.
close.salesorderid = new Lookup();
close.salesorderid.type = EntityName.salesorder.ToString();
close.salesorderid.Value = created.id;
// Create the request object.
CancelSalesOrderRequest cancel = new CancelSalesOrderRequest();
// Set the properties of the request object.
cancel.OrderClose = close;
cancel.Status = -1;
// Execute the request.
CancelSalesOrderResponse canceled = (CancelSalesOrderResponse) service.Execute(cancel);
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials
' Create the order close activity object.
Dim close As New orderclose()
'Set the properties of the order close object.
close.subject = "orderclose"
'Create a Lookup for the sales order being canceled.
close.salesorderid = New Lookup()
close.salesorderid.type = EntityName.salesorder.ToString()
close.salesorderid.Value = created.id
' Create the request object.
Dim cancel As New CancelSalesOrderRequest()
' Set the properties of the request object.
cancel.OrderClose = close
cancel.Status = -1
' Execute the request.
Dim canceled As CancelSalesOrderResponse = CType(service.Execute(cancel), CancelSalesOrderResponse)
See Also
Concepts
Reference
.gif)