[英]How to prevent Dynamics CRM 2015 from creating an opportunity when a lead is qualified?
[英]Get accountID when creating lead in Dynamics CRM
我有一个插件,可以在创建lead
时触发,并希望获取lead
与parentaccountid
相关的帐户的ID
。 我可以打印"subject"
作为lead
但是当涉及到"parentaccountid"
我收到消息"Microsoft.Xrm.Sdk.EntityReference"
,我猜它为null
吗? 奇怪的是,当我在FetchXML Builder中查看潜在客户记录时, parentaccountid
有一个值。
Guid leadId = new Guid(context.OutputParameters["id"].ToString());
ColumnSet cols = new ColumnSet(
new String[] { "subject", "parentaccountid" });
var retrievedLead = service.Retrieve("lead", leadId, cols);
tracingService.Trace(retrievedLead["subject"].ToString());
var accountId = retrievedLead["parentaccountid"];
tracingService.Trace(accountId.ToString());
使用以下语法获取值。
EntityReference lookupRef = retrievedLead.GetAttributeValue<EntityReference>("parentaccountid");
if (lookupRef != null)
Guid accountId = lookupRef.Id;
要么
var accountId = ((EntityReference)retrievedLead["parentaccountid"]).Id;
您可以使用以下代码
Guid ContactId = ((EntityReference)retrievedLead.Attributes["parentaccountid"]).Id;
string PrimaryContact = ((EntityReference)retrievedLead.Attributes["parentaccountid"]).Name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.