簡體   English   中英

Microsoft Dynamics CRM插件:從查找字段檢索屬性

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM