Tuesday, May 29, 2012

CRM 2011 Plug-in to change the status of a record.

Lets take Lead entity as an example in this exercise. The status of lead record will get changed when lead gets converted(qualified) to Account or Contact. We have programmatically done Account record creation from Lead in our previous post and here we can change the status of lead record programmatically through Plug-in as in below code.

//Create reference and add- using Microsoft.Crm.Sdk.Messages;
Entity lead = (Entity)context.InputParameters["Target"];

//Set State and Status of record to Qualified
SetStateRequest setStateRequest = new SetStateRequest() {
    EntityMoniker = new EntityReference {
        Id = lead.Id, LogicalName = "lead"
    },
    State = new OptionSetValue(1),
    Status = new OptionSetValue(-1)
 };
 service.Execute(setStateRequest);

No comments:

Post a Comment