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

Show multiple relationship records in single view

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

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

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

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

你不能这样做 out-of-the-box 因为 sub-grid 只支持一个 1:N 关系。您可以通过创建自定义 FetchXml 并通过 JavaScript 修改 sub-grid 来执行此操作,因为查询可能是通过 FetchXml 进行的,并且可以在高级查找中构建。

关注此 blog article 以获取有关设置 sub-grid.

的 FetchXML 的信息

您需要在您的表单上使用类似于此的加载函数:

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 查询的高级查找是: