The latest version of Microsoft Dynamics CRM 2015 (pre-release) introduces some improvements to the SDK to simplify common operations. In this post, we will look at how the UpdateRequest has been changed to allow us to perform specialised operations in a simple manner.
In previous versions of Microsoft Dynamics CRM, it was not possible to change the state of a record using the UpdateRequest. Instead, developers have to rely on the specific SetStateRequest to achieve this simple task.
The following code snippet is an example of how we would create a new Account, and then use the UpdateRequest to change the state of the Account to Inactive.
Note: The crmService variable is of type IOrganizationService.
Entity account = new
account["name"] = "Magnetism";
Guid id = crmService.Create(account);
account["accountid"] = id;
account["statecode"] = new OptionSetValue(1); // inactive
account["statuscode"] = new OptionSetValue(2);
Previous versions of Microsoft Dynamics CRM
In previous versions of Microsoft Dynamics CRM, we can see here that an error occurs, but it doesn't tell us that we have to use the SetStateRequest to change the state of the Account. The Account remains in an active state.
Microsoft Dynamics CRM 2015 Pre-release
In the Microsoft Dynamics CRM 2015 Pre-release, the UpdateRequest allows us to change the state of the Account to inactive without any errors.
The following list describes the deprecated request messages which can now be achieved using the UpdateRequest.
Note: Although the link above states that these messages are deprecated, it was still possible to execute these requests at the time this post was written.