我为一个服装活动实体创建了一个新的动态CRM 2011插件。
这个新的活动有"to“字段,如电子邮件和其他一些活动。
插件正在为活动创建和更新步骤。
我的问题是,当我想得到"to"
字段值时,下面的代码行返回假值,我不知道我做了什么。实际上,我可以获取其他自定义字段,而只有"to"
字段不能工作。
if (entity3.Attributes.Contains("to"))
这是完整的代码:
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))
}
知道我该怎么做才能纠正插件吗?
发布于 2013-11-04 05:17:26
您的问题和答案很难理解,因为您的英语可能需要一些工作,但我相信您的问题是,您正在寻找一个属性的目标值,但尚未设置。如果没有设置或更新属性,则该属性将不会显示在插件的目标中。正如@AndyMeyers所说,您应该使用PreImage
和PostImage
图像来定义在插件处理过程中始终希望包含哪些属性。
发布于 2013-11-03 06:29:32
所以我解决了我的问题。我创建了两个步骤,用于创建和更新。
当我禁用Create步骤并为update步骤创建预映像时,插入fetch to
字段并显示值。
https://stackoverflow.com/questions/19753070
复制相似问题