![](/img/trans.png)
[英]How to get the option set from a field in an entity in CRM 2011 using crm sdk and C#
[英]How to set value of lookup field in a new entity in CRM using C#
我正在嘗試通過以下代碼更新 CRM 中的查找字段。
HospitalOfBirth
我從在線文章中引用並在下面起草了我的代碼。
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
分配一個值,並使用 hospitalName 更新它嗎?
您不能通過顯示名稱文本設置查找值,您需要查找 Id(外鍵)來實現它。
如果您只有hospitalName
而不是hospitalId
,那么您必須通過使用FetchXml或QueryExpression通過傳遞hospitalName
過濾器來查詢Hospital
實體的 GUID。
Person.Attributes[Person.HospitalOfBirth] = new EntityReference("Hospital", Hospitalid);
Entity Person = new Entity("Person");
Person.Attributes[Person.HospitalOfBirth] = new EntityReference("Hospital", Person.Id);
Person.Id = **<<Guid of the Person record you need to update>>**
helper.GetOrganizationService().Update(Person);
您需要在實體 object 中提供要更新的記錄的 guid。
希望這可以幫助 !!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.