在单个视图中显示多个关系记录

时间:2015-01-27 10:10:52

标签: dynamics-crm

我有一个与父帐户和组织有N:1关系的实体(资产)(两个帐户实体都相同)

在帐户实体中,我可以看到通过父帐户链接到它的资产,或通过组织帐户链接到它的资产,但不能同时看到两者(据我所知)。

我无法更改架构,将父帐户作为一个实体,将组织帐户作为另一个实体。

是否可以在一个子网格中显示两种关系,或者我纯粹仅限于在帐户实体上有两个单独的子网格?

1 个答案:

答案 0 :(得分:3)

由于子网格仅支持单个1:N关系,因此无法开箱即用。您可以通过创建自定义FetchXml并通过JavaScript修改子网格来实现此目的,因为查询可能是通过FetchXml进行的,并且可以在高级查找中构建。

关注此blog article以获取有关设置子网格的FetchXML的信息。

您的表单上需要一个on load功能,类似于:

function filterSubGrid() {
var accountsGrid = document.getElementById("accounts"); //grid to filter
if (accountsGrid == null) { //make sure the grid has loaded
    setTimeout(function () {
        filterSubGrid();
    }, 2000); //if the grid hasn’t loaded run this again when it has
    return;
}

var contactValue = Xrm.Page.getAttribute("primarycontactid").getValue(); //field to filter by

var contactId = "00000000-0000-0000-0000-000000000000"; //if filter field is null display nothing
if (contactValue != null) {
    var contactId = contactValue[0].id;
}

//fetch xml code which will retrieve all the accounts related to the contact
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
    "  <entity name='account'>" +
    "    <attribute name='name' />" +
    "    <attribute name='address1_city' />" +
    "    <attribute name='primarycontactid' />" +
    "    <attribute name='telephone1' />" +
    "    <attribute name='accountid' />" +
    "    <order attribute='name' descending='false' />" +
    "    <filter type='and'>" +
    "      <condition attribute='primarycontactid' operator='eq' uitype='contact' value='" + contactId + "' />" +
    "    </filter>" +
    "    <link-entity name='contact' from='contactid' to='primarycontactid' visible='false' link-type='outer' alias='accountprimarycontactidcontactcontactid'>" +
    "      <attribute name='emailaddress1' />" +
    "    </link-entity>" +
    "  </entity>" +
    "</fetch>";

accountsGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
accountsGrid.control.refresh(); //refresh the sub grid using the new fetch xml
}

除了你需要类似的FetchXML:

var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"  <entity name='new_asset'>" +
"    <attribute name='new_assetid' />" +
"    <attribute name='new_name' />" +
"    <attribute name='createdon' />" +
"    <order attribute='new_name' descending='false' />" +
"    <filter type='or'>" +
"      <condition attribute='new_organizationaccount' operator='eq' value='" + accountId + "' />" +
"      <condition attribute='new_parentaccount' operator='eq'value='" + accountId + "' />" +
"    </filter>" +
"  </entity>" +
"</fetch>";

获取FetchXML查询的高级查找是:

enter image description here