CRM 2016: Changing state attributes is not allowed in create stage 20 plugins

Having recently upgraded our ISV Solution from both CRM 2013 and CR 2015 to CRM 2016, we started to receive the following error, when one our our Pre-Operation(Create) Plugin Steps fired;

“Changing state attributes is not allowed in create stage 20 plugins”

Basically, the plugin on create of a new Entity records was setting the “Status Reason” based on the Status Reason of a “parental related” entity’s Status Reason.

Now this code (below) works completely fine in both CRM 2013 and 2015, however causes issues in CRM 2016.

//DD Contract - Active
entity.Attributes.Add("statuscode", new OptionSetValue(1));

A search of the web resulted in little or no information about this issue in CRM 2016, so my approach was to move the specific code that set the Status Reason to a “Post-Operation” and use SetStateRequest.

The down-side of this, is the extra operation step that is required to achieve the same result, which previously was achievable in a single step.

Advertisements

One thought on “CRM 2016: Changing state attributes is not allowed in create stage 20 plugins”

  1. I recommend against using SetStateRequest in CRM 2015 Update 1 and later since it has been deprecated[https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.setstaterequest.aspx]. You should use an UpdateRequest instead [https://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.updaterequest.aspx]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s