Cancels a contract or salesorder
//#Cancels a Contract
// 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://: /mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the cancel request for a previously created contract
CancelContractRequest contactCancelationRequest = new CancelContractRequest();
// Set the properties for the request
contactCancelationRequest.ContractId = new Guid("C15AF217-C17E-DA11-B90F-000874DE7397");
contactCancelationRequest.CancelDate = new CrmDateTime();
contactCancelationRequest.CancelDate.Value = DateTime.Now.ToString();
contactCancelationRequest.Status = 5;
// Execute the request
service.Execute(contactCancelationRequest);
The following code example demonstrates how to cancel a sales order.
//# cancel a sales order.
// 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://: /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);