by Danny Varghese 03.06.09
One of the least published example of CRM code is deactivating an entity, probably because it's not used as often as creating, updating or retrieving entities. Below is an example I've used on several occasions to deactivate an entity:
1:
2: public void DeactivateEntity(Guid entityId)
3: {
4: //variable initialization
5: SetStateDynamicEntityRequest deactivateReq = new
6: SetStateDynamicEntityRequest();
7: //deactivate the cloned assignment
8: deactivateReq = new SetStateDynamicEntityRequest();
9: deactivateReq.State = "Inactive";
10: deactivateReq.Status = 2;
11: deactivateReq.Entity = new Moniker();
12: deactivateReq.Entity.Name = <entity name>
13: deactivateReq.Entity.Id = entityId;
14: //execute the deactivation request
15: service.Execute(deactivateReq);
16: }
No comments:
Post a Comment