Microsoft Dynamics CRM 2015 - 需要具有子网格查找过滤器

时间:2016-05-18 07:07:16

标签: dynamics-crm

Microsoft Dynamics CRM 2015 - 需要过滤子网格上的查找 我正在使用的Javascript代码:

function SetCustomLookUp() {
    debugger;
    lookupFieldObject = Xrm.Page.data.entity.attributes.get('account');
    if (lookupFieldObject.getValue() != null) {
        entityId = lookupFieldObject.getValue()[0].id;
        entityName = lookupFieldObject.getValue()[0].entityType;
        entityLabel = lookupFieldObject.getValue()[0].name;
    }

    var filterXML = [
            '<filter type="and">',
            '<condition attribute="parentcustomerid" value="{54BC1539-C29C-E511-80E9-3863BB2E6258}" operator="eq"/>',
            '</filter>'
        ].join('\n');
var Subgrid = Xrm.Page.getControl("Contacts");
    document.getElementById("Contacts").addEventListener("click", function () {
        setTimeout(function () {
            var gridControl = Xrm.Page.getControl("Contacts");
            var me = gridControl.$c_0.$N_4.$Y_3;
            me.addPreSearch(function () {
                me.addCustomFilter(filterXML);
            });
        }, 2000);
    });
}

错误:&#34;无法读取属性&#39; addEventListener&#39; of null&#34;

2 个答案:

答案 0 :(得分:0)

我使用了这段代码并且你出现了错误,原因是:

子网格在绘制所有表单的末尾绘制,然后你必须在子网格绘制时添加这个偶数点击

我为此写了一个小代码:

var objSubGrid = document.getElementById("subgrid_name");

//CRM loads subgrid after form is loaded.. so when we are adding script on form load.. need to wait until sub grid is loaded. 
// that's why we are adding a delay..
if (objSubGrid == null) {
    setTimeout(functionxxx, 2000);
    return;
} else {

答案 1 :(得分:0)

以下文章包含答案 - http://www.magnetismsolutions.com/blog/paulnieuwelaar/2016/06/20/filter-n-n-add-existing-lookup-dynamics-crm-2016-turbo-forms

To Modarators - 是的,我知道建议重新输入文章中提到的所有内容,但我很确定该文章将在线提供很长时间,因此我不会重新打字,因为它没有对我有意义。