Hi,

We can Activate\Deactivate record using “SetStateRequest“. Below is the code snippet.

private void SetEntityStatus(IOrganizationService service, Guid recordGUID, string entityName)        {

SetStateRequest setState = newSetStateRequest();

setState.EntityMoniker = newEntityReference();

//Pass GUID of the record to be activated or Deactivated

setState.EntityMoniker.Id = recordGUID;

setState.EntityMoniker.Name = entityName;

setState.EntityMoniker.LogicalName = entityName;

//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)

setState.State = new OptionSetValue();

setState.State.Value = 0/1;

//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)

setState.Status = new OptionSetValue();

setState.Status.Value = 1/2;

SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);

}

Hope it helps 🙂

Advertisements
Advertisements

4 responses to “Activate or Deactivate record in CRM 2011”

  1. Jaques Els Avatar
    Jaques Els

    What permissions to you need to activate / deactivate a lead, I want to stop someone activating someone else (owner)’s records

    1. Rajeev Pentyala Avatar

      Hi,
      I dont think there is a privilege for setting the state of a record, if you have the update privilege then you will be able to activate/deactivate.

      You can use approach mentioned in the below article to restrict the activation/deactivation from Form using jscript.
      https://rajeevpentyala.wordpress.com/2011/12/13/jscript-validation-on-activationdeactivation-of-record-in-crm-2011/

  2. સર્જનWebDev (@sarjanwebdev) Avatar

    What stops you from writing this?
    service.Execute(new SetStateRequest()
    {
    EntityMoniker = new EntityReference(entityName, recordGUID),
    State = new OptionSetValue(1), //Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
    Status = new OptionSetValue(2) //Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
    });

    1. Rajeev Pentyala Avatar

      That’s another way of instantiating of ‘SetStateRequest’ object. But to elaborate each step I had to write the code as mentioned in article

Leave a reply to Jaques Els Cancel reply