CRM 2011: Set EntityState using SetStateRequest

/ Published in: C#
Save to your folder(s)

How to change Entity StateCode (Status) using SetStateRequest

Copy this code and paste it in your HTML
  1. // Refer
  2. // for StateCode's (Status) and StatusCode's (Status Reason)
  4. IOrganizationService service;
  5. new_entity record; // a record of new_entity, can be any Entity
  7. var setStateRequest = new SetStateRequest();
  8. setStateRequest.EntityMoniker = new EntityReference(record.LogicalName, record.Id);
  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);
  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);
  17. var response = (SetStateResponse)service.Execute(setStateRequest);

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.