To programmatically release a contract that was put on hold in Microsoft Dynamics CRM 3.0, you must take advantage of the Microsoft Dynamics CRM Web service and its Execute message. Before you can release a contract that was put on hold, you must change the state of the contract. The Microsoft Dynamics CRM 3.0 SDK contains information about the SetStateContract message to help you change the state of a contract. You can specify the new state, and you can provide a status reason that accompanies this new state.
When you use the Microsoft Dynamics CRM 3.0 SDK to programmatically release a contract, you must set the state of the contract to Invoiced instead of Active. Microsoft Dynamics CRM disallows you to change a contract's state from OnHold to Active. If you try to change a contract's state from OnHold to Active, you receive the following error message if your code encounters a SOAPException exception:
The target state is invalid. The target state may not exist or the system does not allow changing to the target state from the current state. Please check the documentation on this state change request. ErrorCode: -2147220970.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide extra functionality or construct procedures to meet your specific requirements.
The following code example illustrates how to programmatically release a contract that was put on hold in Microsoft Dynamics CRM 3.0.
try
{
CrmService service = new CrmService();
service.Credentials=System.Net.CredentialCache.DefaultCredentials;
SetStateContractRequest change = new SetStateContractRequest();
change.ContractState = ContractState.Active;
change.ContractStatus=-1;
//Set EntityId to GUID of the contract being released.
change.EntityId=new Guid("ED90535A-4FA6-DB11-B75B-000874DE7397");
SetStateContractResponse changed = (SetStateContractResponse)service.Execute(change);
Console.WriteLine("Changed status successfully.");
}
catch (System.Web.Services.Protocols.SoapException err)
{
MessageBox.Show(err.Detail.OuterXml.ToString());
}