如何传递实体引用以在 Microsoft Dynamics 365 CRM 中的查找字段上添加属性值

How to pass an EntityReference to add attribute value on a lookup field in Microsoft Dynamics 365 CRM

提问人:HH44 提问时间:5/23/2020 最后编辑:marc_sHH44 更新时间:5/24/2020 访问量:4082

问:

Entity contact = new Entity("contact");
contact.Attributes.Add("fullname", "h api test");
contact.Attributes.Add("emailaddress1", "[email protected]");
contact.Attributes.Add("telephone1", "1");

contact.Attributes["parentcusotmerid"] = new EntityReference("Organization", );

Guid contactId = m_OrgServ.Create(contact);
Console.WriteLine(contactId);

我要设置的查找字段

查找字段的逻辑名称为 ,并且parentcusotmerid

m_OrgSerc.create 

基本上是

Service.create

我正在为字段设置属性值,它适用于我输入值的普通文本框,但是对于查找值,它不起作用。我知道查找字段的类型是 ,所以我需要知道查找所指向的实体和记录。EntityReferenceLogicalNameId

我已经尝试过了,但现在要求组织字段的 GUID,所以我不确定我是否以正确的方式进行?

Microsoft-Dynamics Dynamics-CRM-WebAPI EntityReference

评论

0赞 ntn 5/23/2020
“parentcustomerID”是对客户和联系人的查找,因此您必须使用任一实体逻辑名称来分配查找值。如果已将帐户实体重命名为组织,则仅更改了显示名称,架构名称保持不变。您是否正在尝试将客户记录与当前联系人相关联?
0赞 HH44 5/24/2020
@Nitin 我只是想创建一个联系人......所以我想将查找字段设置为一个值。组织已经创建,我只想将其与我正在创建的联系人相关联。对不起,这是你要问的吗?
0赞 minohimself 5/24/2020
@HH44 不能将“parentcustomerid”设置为“organization”。它是特殊的引用字段,采用“客户”或“联系人”实体引用作为参数。

答:

2赞 minohimself 5/24/2020 #1

不能将“parentcustomerid”设置为 organization。它是特殊的引用字段,采用“客户”或“联系人”实体引用作为参数。

如果你想设置它,你可以这样

contact.Attributes["parentcusotmerid"] = new EntityReference("account", Guid.NewGuid());

contact.Attributes["parentcusotmerid"] = new EntityReference("contact", Guid.NewGuid());

其中 Guid.NewGuid() 是要引用的客户或联系人的 Guid

评论

0赞 HH44 5/24/2020
但正如你从我上传的图像中看到的那样。我想将“parentcustomerid”的“组织名称”字段设置为值“BAE Systems plc”......因此,在您给出的这段代码中,我可以指定..所以这就是被关注和选择的价值?
0赞 Arun Vinoth-Precog Tech - MVP 5/24/2020
@HH44将父客户查找重命名为“组织”,则如果已创建“BAE 系统”帐户记录,则必须获取该记录的 GUID。具有实体引用的 guid 是设置它的唯一方法。我们不能只用名字来设置。
0赞 minohimself 5/24/2020
正如 Arun 所说,如果 BAE 系统记录的 GUID 已存在,请将 referenz 设置为帐户