Updating a Picklist Attribute from within a Plugin


Just a sample code for updating a picklist attribute for an entity instance.

  public void  Execute(IPluginExecutionContext context)
DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties["Target"];
if (entity.Name == "new_test")
// Post Create event so get the guid from Output Parameters
Guid testId = (Guid)context.OutputParameters.Properties["id"];

ICrmService crmService = context.CreateCrmService(true);
DynamicEntity myTest = new DynamicEntity();
myTest.Name = "EntityName";

// Set the key property
KeyProperty myTestGuid = new KeyProperty();
myTestGuid.Name = "EntityPrimaryKeyID";
Key myTestKey=new Key();
myTestKey.Value = testId;
myTestGuid.Value = myTestKey;

// Picklist property to be updated
PicklistProperty myPP = new PicklistProperty();
myPP.Name = "new_picklist";
myPP.Value = new Picklist();
myPP.Value.name = "nameOfThePicklistValue";
// picklist value
myPP.Value.Value = 2;
catch (SoapException ex)

    TextWriter log1 = TextWriter.Synchronized(File.AppendText(@"C:\g.txt"));
    log1.WriteLine("MyMessage exception :-" + ex.Detail.InnerXml );




Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

1 thought on “Updating a Picklist Attribute from within a Plugin”

Share your thoughts

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