javascript - 如何在 Dynamics CRM 中显示帐户和子帐户的联系人

标签 javascript crm microsoft-dynamics dynamics-crm-2015 fetchxml

我分享这个是因为我花了很长时间才找到一种显示父帐户及其所有子帐户的所有联系人的好方法。这样,当查看子帐户时,它只会显示该帐户的联系人,但对于主帐户,它将显示该帐户的联系人及其子帐户的联系人。

最佳答案

首先在帐户表单编辑器中插入一个联系人子网格,为其命名,并为其指定一个要显示的标签。有如下图所示的选项。

Subgrid options

然后将以下代码添加为网络资源 (JavaScript)

function GetContacts() {

// get Contacts Sub grid
var accountChildContactsGrid = window.parent.document.getElementById("whatever your sub grid name is")


// Get the ID of the current account
var rootAccountID = Xrm.Page.data.entity.getId();

// Check that the subgrid is ready
if (accountChildContactsGrid == null){
    setTimeout('GetContacts()',1000);
    return;
}

// Construct FetchXML for contacts in this account and its child accounts
var fetchXml = "<fetch version='1.0' mapping='logical'>";
fetchXml += "<entity name='contact'>";
fetchXml += "<attribute name='fullname'/>";
fetchXml += "<attribute name='emailaddress1'/>";
fetchXml += "<order attribute='fullname' descending='false' />";
fetchXml += "<link-entity name='account' from='accountid' to='parentcustomerid' link-type='inner' >";
fetchXml += "<filter type='and'>";
fetchXml += "<condition attribute='accountid' operator='eq-or-under' value='" + rootAccountID + "' />";
fetchXml += "<condition attribute='accountid' operator='not-null' />";
fetchXml += "</filter>";
fetchXml += "</link-entity>";
fetchXml += "</entity>";
fetchXml += "</fetch>";

// make sure control is ready and set data and refresh the subgrid
if (accountChildContactsGrid.control != null){  
    accountChildContactsGrid.control.SetParameter("fetchXml", fetchXml);
    accountChildContactsGrid.control.refresh();
}
else{
    setTimeout('GetContacts()',1000);
}

}

最后,返回帐户表单编辑器,转到表单属性并将资源添加到库中,然后添加一个 onload 操作,该操作将调用我们的 GetContacts() 函数,如下图所示

enter image description here

我希望这对某人有帮助

注意:此解决方案适用于 Dynamics CRM Online 2015 (7.1) 注意2:您需要已经设置了层次关系功能才能使其发挥作用

关于javascript - 如何在 Dynamics CRM 中显示帐户和子帐户的联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34867988/

相关文章:

c# - 在 dynamics crm 2011 中创建联系人时出现一般 SQL 错误

javascript - 溢出隐藏内容(滚动时应该出现)

javascript - 无法使用 knockout.js 从下拉列表中更新模型

dynamics-crm - 当我能够设置值时,为什么我的 Entity.Contains(attributes Field) 返回 false?

c# - 使用通过 ADFS (Ws-Federation) 保护的 Dynamics CRM Web API

javascript - 如何使文本字段适合 Dynamics CRM 2011

c# - 以编程方式查看 CRM 报告而无需访问 Reporting Server

dynamics-crm-2011 - Dynamics CRM 2011 如何将字符串字段设置为唯一?

javascript - 翻转效果条件

javascript - Vuetify form .$refs validate 不是函数