[英]MS CRM c#: Pickup string guid from dictionary and use it to populate lookup field when creating a new CRM record
I'm a total newbie to C#. 我是C#的新手。 Trying to create a custom entity record.
尝试创建自定义实体记录。 I have created a windows service that can connect and create the CRM custom entity record but only if I hard code the GUID's for the lookups.
我已经创建了一个Windows服务,该服务可以连接并创建CRM自定义实体记录,但前提是我必须对查询的GUID进行硬编码。
How can I pickup the GUID from the dictionary and turn it into a lookup like I do for the text fields? 如何从字典中提取GUID并将其转换为类似于文本字段的查找? snippet is below.
以下是摘要。
aar_assessmentresult aar_assessmentresult = new aar_assessmentresult();
foreach (string key in dicColumnList.Keys)
{
colVal = string.Empty;
if (dicColumnList.TryGetValue(key, out colVal))
{
//this works
if (key.ToString() == "AssessmentResultName")
{
aar_assessmentresult.aar_name = colVal.Replace("'", "''");
}
//Code breaks here
if (key.ToString() == "ContactID")
{
Guid contactid = new Guid();
aar_assessmentresult.aar_contactid = new Lookup();
aar_assessmentresult.aar_contactid.type = "contact";
aar_assessmentresult.aar_contactid.Value = contactid;
}
}
}
crmService.Create(aar_assessmentresult);
when you do this: 当您这样做时:
Guid contactid = new Guid();
aar_assessmentresult.aar_contactid = new Lookup();
aar_assessmentresult.aar_contactid.type = "contact";
aar_assessmentresult.aar_contactid.Value = contactid;
you are trying to set a contact lookup with an invalid reference since your variable contactid does is not related to an existing contact record. 您正在尝试使用无效的引用设置联系人查找,因为您的变量contactid与现有的联系人记录无关。 You must create the contact in before or refer to a valid existing contact before doing
您必须在之前创建联系人或参考有效的现有联系人,然后再进行操作
crmService.Create(aar_assessmentresult);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.