Example Of Deactivating An Entity

by Bill Owens 31. October 2009 05:47

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: }


Tags: , ,

CRM 4.0

Page List

About the author

I work for a consulting firm in Dublin Ohio called Affiliated Resource Group. For the last five years I have been spearheading our Microsoft Dynamics CRM practice. I have a deep appreciation for the Microsoft CRM platform and I am very excited about it. You might even describe me as a Microsoft CRM Advocate. I have many battle scars from my experience with the product and I’m constantly being asked questions about CRM and how-to-do something in it. Hence, this BLOG is to help disseminate that knowledge and information to everyone. As of last year I was posting links to many other blogs to help spread the knowledge, but now with the community.dynamics.com doing that for me, I will be following that practice unless a really juicy article catches my eye. Many people have asked where my post are for the first half of 2010, my company had me posting to another blog and maintain two was near impossible. I am now down to just this blog. So good luck and I hope that this blog may help in some way. If you have suggestions or questions, please email me them.

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 BillOnCRM