Updating a Picklist Attribute from within a Plugin
Hi,
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;
myTest.Properties.Add(myTestGuid);
// 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;
myTest.Properties.Add(myPP);
try
{
crmService.Update(myTest);
}
catch (SoapException ex)
{
TextWriter log1 = TextWriter.Synchronized(File.AppendText(@"C:\g.txt"));
log1.WriteLine("MyMessage exception :-" + ex.Detail.InnerXml );
log1.Close();
}
}
}
}
Bye…
Filed under: Microsoft Dynamics CRM Tagged: CRM, CRM 4.0
This was originally posted here.

Like
Report
*This post is locked for comments