I have a Dynamics 365 Activity Task record that contains a description with the value "Test Description Value". I want to retrieve this value in a plug-in.
My main code is outlined below.
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService((typeof(IPluginExecutionContext)));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity task = (Entity)context.InputParameters["Target"];
if (task.LogicalName == "task")
{
ColumnSet cs = new ColumnSet(new string[] { "description", "ownerid" });
service.Retrieve("task", task.Id, cs);
foreach (KeyValuePair<String, Object> attribute in task.Attributes)
{
tracingService.Trace(attribute.Key + ": " + attribute.Value);
}
}
}
}
Iterating the foreach loop reveals that the task.Attributes
does not contain a key for description, nor can I get the current value of the description using task["description"]
. Both return a System.Collections.Generic.KeyNotFoundException.
Is it possible to get the current value of the description field of an Activity Task record in a plug-in? How?