CRM 2011 – Setting a state and status of an entity using a plugin

Good one.

Here is code to change status

public void updateChargeState(Guid chargeId)
{

SetStateRequest setState = new SetStateRequest();

setState.EntityMoniker = new EntityReference();

setState.EntityMoniker.Id = chargeId;

setState.EntityMoniker.Name = “Charge”;

setState.EntityMoniker.LogicalName = new_charge.EntityLogicalName;

setState.State = new OptionSetValue(1);
setState.Status = new OptionSetValue(951850001);
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}

Hosk's Dynamic CRM Blog

I had created a charge entity.  I was creating charge entities of certain values when certain things had happened on regarding cases.  When a case was created it created a charge entity linked to the case, account and product etc for a certain value.

Then when other status were reached a workflow would fire off and create more charge entity’s.  Then at a certain point the user wanted to create an invoice for all the charge entities which had not been assigned to an invoice.

So I created a plugin which when a new invoice is created it goes off and searches for all the charge entities which are not been associated with an invoice.  It then assigns the newly created invoice, adds a date and then I wanted to make the charge entity inactive.  I created a new inactive state called Invoiced.  The reason I wanted to do this…

View original post 159 more words

Advertisements

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 )

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