[英]Best way to pass a Lookup GUID while creating a new Opportunity entity
我有一個 MVC 表單,其中包含我用作搜索框的@Html.TextBox
。 當我的用戶單擊搜索按鈕時,他們可以獲得從 CRM 返回的數據構建的選項列表。 我正在捕獲所選項目的 GUID……一件好事。
如何格式化數據?
當我的用戶提交表單時,我如何格式化 GUID,以便正在創建的商機實體可以將選定的 GUID 分配給查找字段(與聯系人關聯)?
以下是我如何提交給 CRM 的簡短示例。 我正在提交 70 多個字段的數據。 Picklist、DateTime、String 字段都可以工作,只是 Lookup 字段我還不能讓它工作。
OrganizationServiceClient client = new OrganizationServiceClient();
Microsoft.Xrm.Sdk.Entity ec = new Entity {
LogicalName = "opportunity"
};
ec.Attributes.Add(new KeyValuePair<string, object>("name", Request.Form["newOppName"]));
ec.Attributes.Add(new KeyValuePair<string, object>("org_managers", Request.Form["selectedGUID"]));
// "org_managers" name for Lookup (simple; dependent on Contact) within Opportunity entity
var OppGUID = await client.CreateAsync(ec);
我嘗試了其他幾種植根於 JavaScript 而不是 C# 的方法,但沒有任何效果。
它被稱為EntityReference
。 它應該像下面這樣分配:
ec[“org_managers”] = new EntityReference(“contact”, new Guid(Request.Form["selectedGUID"]));
或者
ec.Attributes[“org_managers”] = new EntityReference(“contact”, new Guid(Request.Form["selectedGUID"]));
或者
ec.Attributes.Add(“org_managers”, new EntityReference(“contact”, new Guid(Request.Form["selectedGUID"]));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.