[英]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.