[英]Best way to pass a Lookup GUID while creating a new Opportunity entity
I have a MVC form that features an @Html.TextBox
that I use as a search box.我有一个 MVC 表单,其中包含我用作搜索框的
@Html.TextBox
。 My user can get a list of options built from the data returned by CRM when they click the search button.当我的用户单击搜索按钮时,他们可以获得从 CRM 返回的数据构建的选项列表。 I'm capturing the GUID of the selected item... a good thing.
我正在捕获所选项目的 GUID……一件好事。
How do I format the data?如何格式化数据?
When my user submits the form, how do I format the GUID so the Opportunity entity being created can assign the selected GUID to the Lookup field (associated with a Contact)?当我的用户提交表单时,我如何格式化 GUID,以便正在创建的商机实体可以将选定的 GUID 分配给查找字段(与联系人关联)?
What follows is a brief example of how I'm doing the submission to CRM.以下是我如何提交给 CRM 的简短示例。 I'm submitting 70+ fields worth of data.
我正在提交 70 多个字段的数据。 The Picklist, DateTime, String fields all of them work, it's just the Lookup fields I can't make it work yet.
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);
I've tried a couple of other methods that are rooted in JavaScript rather than C#, but nothing works.我尝试了其他几种植根于 JavaScript 而不是 C# 的方法,但没有任何效果。
It's called EntityReference
.它被称为
EntityReference
。 It should get assigned like below:它应该像下面这样分配:
ec[“org_managers”] = new EntityReference(“contact”, new Guid(Request.Form["selectedGUID"]));
Or或者
ec.Attributes[“org_managers”] = new EntityReference(“contact”, new Guid(Request.Form["selectedGUID"]));
Or或者
ec.Attributes.Add(“org_managers”, new EntityReference(“contact”, new Guid(Request.Form["selectedGUID"]));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.