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