Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Dynamics CRM中显示帐户和子帐户的联系人_Javascript_Crm_Microsoft Dynamics_Dynamics Crm 2015_Fetchxml - Fatal编程技术网

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

Javascript 如何在Dynamics CRM中显示帐户和子帐户的联系人,javascript,crm,microsoft-dynamics,dynamics-crm-2015,fetchxml,Javascript,Crm,Microsoft Dynamics,Dynamics Crm 2015,Fetchxml,我之所以分享这个,是因为我花了很长时间才找到一个好方法来显示父帐户及其所有子帐户的所有联系人。因此,当查看子帐户时,它将仅显示该帐户的联系人,但对于主帐户,它将显示该帐户的联系人及其子帐户的联系人。首先在帐户表单编辑器中插入联系人的子网格,命名它,给它一个要显示的标签。有如下图所示的选项 然后将下面的代码添加为web资源(JavaScript) 函数GetContacts(){ //获取子网格中的联系人 var accountChildContactsGrid=window.parent.do

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

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

然后将下面的代码添加为web资源(JavaScript)

函数GetContacts(){ //获取子网格中的联系人 var accountChildContactsGrid=window.parent.document.getElementById(“无论您的子网格名称是什么”) //获取当前帐户的ID var rootAccountID=Xrm.Page.data.entity.getId(); //检查子网格是否已准备就绪 if(accountChildContactsGrid==null){ setTimeout('GetContacts()',1000); 返回; } //为此帐户及其子帐户中的联系人构造FetchXML var fetchXml=“”; fetchXml+=“”; fetchXml+=”

我希望这对某人有帮助

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

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);
}