[英]Microsoft Dynamics CRM Plugin: Retrieve Attribute from Look Up Field
我在CRM中是新的。 我创建了两个实体:订单和产品。 在订单实体上,有一个查找字段可触发产品实体。 我尝试通过查找字段从产品中获取产品数量,然后将其粘贴到订单实体中的字段中。 这是我尝试的代码:
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.Attributes.Contains("new_productname"))
{
Entity productreference = service.Retrieve("new_callistyproduct", ((EntityReference)entity["new_productname"]).Id, new ColumnSet(true));
if (productreference.Attributes.Contains("new_productquantity"))
{
if (entity.Attributes.Contains("new_numberofproduct"))
entity["new_numberofproduct"] = productreference.GetAttributeValue<Decimal>("new_productquantity");
else
entity.Attributes.Add("new_numberofproduct", productreference.GetAttributeValue<Decimal>("new_productquantity"));
}
}
}
每当我创建新记录时,我都希望此插件正常工作。 所以我将此插件注册为Pre-create事件。 但是,当我尝试创建记录时。 该插件未从productquantity字段中获取价值。 因此,我尝试将此插件作为Pre-Update事件运行。 根据我之前创建的记录,我将查找值从产品A更改为产品B。插件的工作是从产品B检索产品数量值。
问题是,如果我希望此插件也可以用于创建前事件,该怎么办。
谢谢
如果要更新目标实体,并让CRM为您执行更新,则必须在“创建前”或“更新前”上注册插件。 如果要对Post事件执行操作,则需要使用IOrganizationService调用Update,只是无法更新Target。 您还需要确保您不会创建无限循环,在该循环中,更新将触发插件,该循环执行另一个触发相同插件的更新,然后执行另一个更新...等等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.