首页 > 解决方案 > 如何传递 EntityReference 以在 Microsoft Dynamics 365 CRM 中的查找字段上添加属性值

问题描述

Entity contact = new Entity("contact");
contact.Attributes.Add("fullname", "h api test");
contact.Attributes.Add("emailaddress1", "hh@devenv1.local");
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

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

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

标签: dynamics-crmmicrosoft-dynamicsdynamics-crm-webapientityreference

解决方案


您不能将“parentcustomerid”设置为组织。它是一个特殊的引用字段,它以 Account 或 Contact 实体引用作为参数。

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

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

或者

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

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


推荐阅读