[Given] CRM Can not read property 'SetParameter' of undefined when screening subgrids

Recently received a development task, need to be screened on the master sub-grids, but there is an interesting bug in the process of writing, specifically about the record:

1, using conventional methods to obtain sub-meshes

The reason for using Microsoft's official code to get sub-mesh will complain Can not read property 'SetParameter' of undefined, unclear is not the current version is not supported by CRM

//获取子网格
var subgrid = Xrm.Page.getControl("new_purchase_order_id").getGrid();

Pictures error

2, the use of unconventional methods to obtain sub-meshes

When acquiring sub-grid use unconventional methods, without error

//获取子网格
var subgrid = window.parent.document.getElementById("new_purchase_order_id");

The correct picture

The following is the complete code:

//显示关联本记录的LC付款方式的且【业务审批表】.{审核状态}==“审核中”或“已审核”的业务审批单,即显示占用LC额度的订单
function filter_new_purchase_order() {
    //获取子网格
    var subgrid = window.parent.document.getElementById("new_purchase_order_id");
    //var subgrid = Xrm.Page.getControl("new_purchase_order_id").getGrid();
    if (subgrid == null) {
        setTimeout(function () {
            filterSubGrid();
        }, 2000); //如果为空再加载
        return;
    }

    //获取所对应的信用证号
    var new_name = rtcrm("#new_name").val();
    var new_letter_credit = rtcrm.retrieve("new_letter_credits?$filter=new_name eq " + "'" + new_name + "'", false);
    var new_letter_credit_id = new_letter_credit.value[0].new_letter_creditid.replace("{", "").replace("}", "");

    //构造fetch查询
    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>\
                            <entity name='new_purchase_order'>\
                                <attribute name='new_purchase_orderid' />\
                                <attribute name='new_name' />\
                                <attribute name='createdon' />\
                                <order attribute='new_name' descending='false' />\
                                <filter type='and'>\
                                    <condition attribute='new_approvalstatus' operator='in'>\
                                        <value>2</value>\
                                        <value>3</value>\
                                    </condition>\
                                </filter>\
                                <link-entity name='new_lc_for_order' from='new_purchase_order_id' to='new_purchase_orderid' alias='aa'>\
                                    <filter type = 'and'>\
                                        <condition attribute='new_letter_credit_id' operator='eq' value='"+ new_letter_credit_id + "' />\
                                    </filter>\
                                </link-entity>\
                            </entity>\
                        </fetch>";

    //执行筛选逻辑
    subgrid.control.SetParameter("fetchXml", fetchXml);
    subgrid.control.refresh();
}
Published 76 original articles · won praise 18 · views 40000 +

Guess you like

Origin blog.csdn.net/Yanzudada/article/details/104887757