Advertisements
Home > CRM 2011, Plug-Ins > Activate or Deactivate record in CRM 2011

Activate or Deactivate record in CRM 2011

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
  1. Jaques Els
    April 2, 2012 at 3:49 PM

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

  2. July 16, 2013 at 1:20 PM

    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)
    });

    • July 16, 2013 at 2:56 PM

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

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: