Dynamics CRM使用N:N关系的相关数据过滤SubGrid

时间:2016-12-08 15:38:00

标签: dynamics-crm crm dynamics-crm-online

我有一个名为“Project”的实体,它与N:1关系的“Account”相关。

我在“项目”和“联系人”之间有N:N关系。因此,对于每个项目,我都可以添加许多联系人。

现在我有一个SubGrid,它显示项目的联系人列表并添加现有的联系人。

问题是:当我使用搜索查找来查找联系人时,我从系统中获取所有联系人

我需要的是:从帐户中获取与项目相关的联系人。

换句话说:对于每个项目,我想从与项目相关的帐户中添加许多联系人

2 个答案:

答案 0 :(得分:0)

您需要为查找控件添加自定义过滤器。

var fetchXml = "<filter type='or'>"; //or 'and' depending if you want more conditions...
fetchXml += "<condition attribute='new_contactAccountField' operator='eq' value='" + yourAccountid + "'/>"; //new_contactAccountField is the field on your contact that links it somehow to the account...
fetchXml += '</filter>';

Xrm.Page.getControl('new_yourContactLookupField').addPreSearch(function () {
    Xrm.Page.getControl('new_yourContactLookupField').addCustomFilter(fetchXml);
});

答案 1 :(得分:0)

您可以使用以下过滤器来过滤子网格:

this.navigateTo = function () {
        var account = getAccountId();

        //define data for lookupOptions
        var lookupOptions =
        {
            defaultEntityType: "project",
            entityTypes: ["project"],
            allowMultiSelect: true,
            searchText: " "
        };

        if (account !== null) {
            lookupOptions.filters = [
                {
                    filterXml: `<filter type='and'><condition attribute='accountid' operator='eq' value='${account}'/></filter>`,
                    entityLogicalName: "project"
                }
            ];
        }

        // Get account records based on the lookup Options
        Xrm.Utility.lookupObjects(lookupOptions).then(
            function (projects) {
                console.log(projects);
            },
            function (error) {
                console.log(error);
            }
        );
    }

不要忘记使用 Ribbon Workbench ,并将事件侦听器添加到您的“添加现有按钮” 。我赶紧让您感到不安,在单击“添加”后此导航不会添加实体,而只会提供您所需的列表。不幸的是,我没有将新实体添加到子网格的代码。