I create a new plugin for dynamic CRM 2011 for a costume Activity Entity.
this new activity have "to" field like Email and some other activities.
plugin are working on Create and Update steps for activity.
my problem is when i want to get "to"
field value the below line of code return false value and i don't know what i have done. in fact i can fetch other custom field and just the "to"
field does not work.
if (entity3.Attributes.Contains("to"))
and this is whole code:
public void Execute(IServiceProvider serviceProvider)
{
if (serviceProvider == null)
{
throw new ArgumentNullException("serviceProvider");
}
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))
{
Entity entity2 = (Entity)context.InputParameters["Target"];
if (entity2.LogicalName == "EntityAtivity")
{
QueryExpression expression3 = new QueryExpression("EntityAtivity");
ColumnSet set2 = new ColumnSet();
set2.AllColumns = true;
expression3.ColumnSet = set2;
ConditionExpression item = new ConditionExpression();
item.AttributeName = "activityid";
CurrentGuid = (Guid)entity2.Attributes["activityid"];
item.Values.Add(this.CurrentGuid);
FilterExpression expression5 = new FilterExpression();
expression5.Conditions.Add(item);
expression3.Criteria = expression5;
EntityCollection entitys2 = service.RetrieveMultiple(expression3);
foreach (Entity entity3 in entitys2.Entities)
{
this.dbGuid = (Guid)entity3.Attributes["activityid"];
if (entity3.Attributes.Contains("to"))
{
try
{
foreach (Entity entity10 in ((EntityCollection)entity3.Attributes["to"]).Entities)
{
this.dbTo.Add(((EntityReference)entity10.Attributes["partyid"]).LogicalName);
this.dbToId.Add(((EntityReference)entity10.Attributes["partyid"]).Id);
}
}
catch (Exception)
{
this.dbTo.Clear();
}
}
} // foreach
}//if (entity2.LogicalName == "EntityAtivity")
}//if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))
}
any know what i should done to correct plugin?
EntityAtivity
isn't a valid name for the entity. When coding it uses the logical name which is all lower case and starts with your prefix like 'new_'. When retrieving values from the record the plugin is firing on you should use the Target input parameter, or register Pre & Post entity images. – Andy MeyersPreImage
andPostImage
names are registered via the plugin tool. You can choose which images you want, what the name is, and what fields are available in them. – Andy Meyers