簡體   English   中英

在Dynamics CRM中創建銷售線索時獲取accountID

[英]Get accountID when creating lead in Dynamics CRM

我有一個插件,可以在創建lead時觸發,並希望獲取leadparentaccountid相關的帳戶的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM