简体   繁体   English

创建新商机实体时传递查找 GUID 的最佳方式

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

相关问题 在新实体中加载导航属性的最佳方法 - Best way to load navigation properties in new entity AutoMapper 没有创建新的映射指南 - AutoMapper not creating new Guid on mapping MS CRM c#:从字典中提取字符串guid,并在创建新的CRM记录时使用它填充查找字段 - MS CRM c#: Pickup string guid from dictionary and use it to populate lookup field when creating a new CRM record 迁移增量ID并转换为Guid的最佳方法 - Best way to migrate increment ID and convert to Guid 存储GUID和DateTime对象列表的最佳方法 - Best way to store a List of GUID and DateTime objects 知道字符串是long还是Guid的最佳方法是什么? - What is the best way to know if a string is a long or a Guid? 将模型传递给MVC6中的新ViewDataDictionary的最佳方法 - Best way to pass a model to a new ViewDataDictionary in MVC6 启动时将数据传递给新ViewModel的最佳方法 - Best Way to Pass Data to new ViewModel when it is initiated 这是使用MVVM设计模式创建新窗口的最佳方法 - Which is the best way for creating new windows using the MVVM design pattern 将现有实体记录(竞争对手)关联到新记录(机会)crm d365 On create message - Associate existing entity records (competitor) to new record (opportunity) crm d365 On create message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM