Thursday, 10 July 2008

Set the State/Status of A Custom Entity in CRM 4.0

The process to set the state and status of a Custom Entity within your plugin code is slighlty different to when setting it for an out of the box system type in CRM 4.0.

You need to use the SetStateDynamicEntityRequest and SetStateDynamicEntityResponse classes rather than the predefined ones like SetStateAccountRequest.

You just define which type of custom entity you are setting the state for and its Unique Identifier (GUID).

SetStateDynamicEntityRequest stateReq = new SetStateDynamicEntityRequest();

stateReq.Entity = new Moniker();

stateReq.Entity.Id = new Guid("The GUID of your Entity instance here");
stateReq.Entity.Name = "your entity Name here";

//Set to Inactive
stateReq.State = "inactive";
stateReq.Status = -1;

//Set to Active
//stateReq.State = "active";
//stateReq.Status = 1;

SetStateDynamicEntityResponse stateSet = SetStateDynamicEntityResponse)crmService.Execute(stateReq);

1 comments:

Anonymous said...

Thanks, handy tip!