There are times when we need to cancel a service order using out custom code. The following code helps us achieve that.
/// Active - 0 => New - 1, Pending - 2
/// Submitted - 1 => In Progress - 3
/// Canceled - 2 => No Money - 4,
/// Fulfilled - 3 => Complete - 100001, Partial - 100002
/// Invoiced - 4 => Invoiced - 100003
try
{
CancelSalesOrderRequest setstate = new CancelSalesOrderRequest
{
RequestName = "CancelSalesOrder",
OrderClose = new OrderClose { SalesOrderId = new EntityReference("salesorder", OrderID)},
Status = new OptionSetValue(status),
};
CancelSalesOrderResponse setstateresponse = (CancelSalesOrderResponse)Service.Execute(setstate);
}
catch (Exception ex)
{
}
/// Submitted - 1 => In Progress - 3
/// Canceled - 2 => No Money - 4,
/// Fulfilled - 3 => Complete - 100001, Partial - 100002
/// Invoiced - 4 => Invoiced - 100003
try
{
CancelSalesOrderRequest setstate = new CancelSalesOrderRequest
{
RequestName = "CancelSalesOrder",
OrderClose = new OrderClose { SalesOrderId = new EntityReference("salesorder", OrderID)},
Status = new OptionSetValue(status),
};
CancelSalesOrderResponse setstateresponse = (CancelSalesOrderResponse)Service.Execute(setstate);
}
catch (Exception ex)
{
}
OrderID = Should be the sales order Guid that we should be cancelling.
Above the code are the statuses that we get for Status field.