问题描述
我正在尝试通过以下代码更新CRM中的查找"字段.
I am trying to update a Lookup field in CRM via the following code.
- 创建一个新实体 Person
- 人员包含来自另一个实体医院 的查找字段
- 要插入的值:hospitalName
HospitalOfBirth
我参考了在线文章,并在下面起草了代码.
I referenced from online articles and drafted my code below.
Entity Person = new Entity("Person");
//do I set the value of the field by the following?
Person.Attributes[Person.HospitalOfBirth] = hospitalName;
Person.Attributes[Person.HospitalOfBirth] = new EntityReference("Hospital", Person.Id);
Person.Id = helper.GetOrganizationService().Create(Person);
我可以知道为 Person 中的查询字段 HospitalOfBirth
分配一个值,并使用医院名称对其进行更新吗?
May I know to assign a value to the lookup field HospitalOfBirth
in Person, and update it with hospitalName?
推荐答案
您无法通过显示名称文本设置查找值,需要使用查找ID(外键)来实现.
You cannot set a lookup value by display name text, you need lookup Id (Foreign key) to achieve it.
如果您只具有 hospitalName
,而没有 hospitalId
,则必须通过执行向 HospitalId
实体查询GUID.使用 FetchXml 或 QueryExpression ,通过传递 hospitalName
过滤器> RetrieveMultiple .
If you just have the hospitalName
and not the hospitalId
, then you have to query the Hospital
entity for the GUID by doing RetrieveMultiple using FetchXml or QueryExpression by passing hospitalName
filter.
Person.Attributes[Person.HospitalOfBirth] = new EntityReference("Hospital", Hospitalid);
这篇关于如何使用C#在CRM中的新实体中设置查找字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!