【问题标题】:How to fill a lookup field via C# Plugin in Dynamics 365 CRM如何通过 Dynamics 365 CRM 中的 C# 插件填充查找字段
【发布时间】:2021-11-18 14:25:21
【问题描述】:

有一个联系实体;在其中一个城市查找字段, 通过控制台应用程序创建新联系人(给定详细信息名字、姓氏、城市)。 我似乎无法理解如何填写查找字段...? 这是我的代码:

// here supposed to pass in addition to lastname, A lookup parameter to fill after finding the contact
static void FillContactLookupByLastname(string lastname /*, Lookup City*/) 
        {
            ConditionExpression condition1 = new ConditionExpression();
            condition1.AttributeName = "lastname";
            condition1.Operator = ConditionOperator.Equal;
            condition1.Values.Add(lastname);

            FilterExpression filter1 = new FilterExpression();
            filter1.Conditions.Add(condition1);

            QueryExpression query = new QueryExpression("contact");
            query.ColumnSet.AddColumns("firstname", "lastname");
            query.Criteria.AddFilter(filter1);

            EntityCollection result1 = crmService.RetrieveMultiple(query);
            Console.WriteLine(); Console.WriteLine("Query using Query Expression with ConditionExpression and FilterExpression");
            Console.WriteLine("---------------------------------------");
            foreach (var a in result1.Entities)
            {
                Console.WriteLine("Name: " + a.Attributes["firstname"] + " " + a.Attributes["lastname"]);
//here after finding the contact with the lastname, it has a lookup field that i need to fill but i dont know how
            }
        }

【问题讨论】:

    标签: c# plugins dynamics-crm crm microsoft-dynamics


    【解决方案1】:

    您可以使用 EntityReference 类处理查找字段。
    以这种方式传递EntityReference 参数

    static void FillContactLookupByLastname(string lastname, EntityReference city) 
    

    然后填写值

    a["city"] = city;
    

    也不要忘记为实体调用Update 方法

    crmService.Update(a);
    

    【讨论】:

      猜你喜欢
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      相关资源
      最近更新 更多