2015-11-19 103 views
0

即时通讯新属性。我创建了两个实体:订单和产品。在订单实体有查看产品实体的字段。我试图通过查找字段从产品获取产品数量,并将其粘贴到订单实体中的字段。这里是我试过的代码:的Microsoft Dynamics CRM插件:在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")); 



       } 

      } 



     } 

我希望这个插件能够在我创建新记录时工作。所以我把这个插件注册为预创建事件。但是,当我尝试创建一个记录。该插件没有从productquantity字段中检索值。 所以,我试图将此插件作为Pre-Update事件运行。在我以前创建的记录,我改变从产品A到B.产品及其工作查找值,该插件检索产品B.

的问题是产品的数量值,我应该怎么做,如果我希望这个插件也适用于预创建事件。

感谢

+0

是查找插件在预操作创建阶段被触发时填充了“new_productname”? –

回答

0

如果要更新目标实体,并有CRM进行更新,你必须要在预创建或预更新注册您的插件。如果您想对Post事件执行操作,则需要使用IOrganizationService调用Update,只是更新Target不起作用。你也想确保你没有创建一个无限循环,其中一个更新触发插件,它执行触发了同一插件另一个更新,执行另一个更新......等等,等等

相关问题