Posted By

toLL on 06/20/12


Tagged

crm entitystate setstaterequest statecode


Versions (?)

CRM 2011: Set EntityState using SetStateRequest


 / Published in: C#
 

How to change Entity StateCode (Status) using SetStateRequest

  1. // Refer http://msdn.microsoft.com/en-us/library/ms914670.aspx
  2. // for StateCode's (Status) and StatusCode's (Status Reason)
  3.  
  4. IOrganizationService service;
  5. new_entity record; // a record of new_entity, can be any Entity
  6.  
  7. var setStateRequest = new SetStateRequest();
  8. setStateRequest.EntityMoniker = new EntityReference(record.LogicalName, record.Id);
  9.  
  10. // State property corresponds to the StateCode of an Entity. Its' shown as the Status in CRM
  11. setStateRequest.State = new OptionSetValue((int)new_entityState.Inactive);
  12.  
  13. // Status property corresponds to the StatusCode of an Entity. Its' shown as the StatusReason in CRM
  14. // set this value to -1 to let the system automatically set the appropiate corresponding status value
  15. setStateRequest.Status = new OptionSetValue(-1);
  16.  
  17. var response = (SetStateResponse)service.Execute(setStateRequest);

Report this snippet  

You need to login to post a comment.