我分享这个是因为我花了很长时间才找到一种显示父帐户及其所有子帐户的所有联系人的好方法。这样,当查看子帐户时,它只会显示该帐户的联系人,但对于主帐户,它将显示该帐户的联系人及其子帐户的联系人。
最佳答案
首先在帐户表单编辑器中插入一个联系人子网格,为其命名,并为其指定一个要显示的标签。有如下图所示的选项。
然后将以下代码添加为网络资源 (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() 函数,如下图所示
我希望这对某人有帮助
注意:此解决方案适用于 Dynamics CRM Online 2015 (7.1) 注意2:您需要已经设置了层次关系功能才能使其发挥作用
关于javascript - 如何在 Dynamics CRM 中显示帐户和子帐户的联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34867988/