Debugging · Dynamics CRM 2011

CRM 2011: EntityState must be set to null, Created (for Create message) or Changed (for Update message)

We were getting this error when creating a new record in CRM 2011 using REST SDK. The new record entity has a post-create plugin that updates a field.

var entity = (Entity)context.InputParameters["Target"];
var mappedEntity = entity.ToEntity<incident>();
mappedEntity.new_x = "abc";

This error was caused by update transaction which needs to be executed on a different context. Since the plugin context has finished executing create on the entity (EntityState = “Created”), CRM is preventing the update transaction to be completed.

The workaround would be doing the update on Pre-Operation stage, or retrieving the entity and update the retrieved entity instead of the entity in plugin context’s InputParameters.

Cheers – Sy


Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s