Retrieve rows in crm2011 subgrid with JScript

前端 未结 4 1041
眼角桃花
眼角桃花 2020-12-20 09:40

As an JScript newbie, I have a problem with a subgrid in MS CRM 2011.

I have a form with a subgrid and in OnSave of that form, I want to loop over all the rows in th

4条回答
  •  余生分开走
    2020-12-20 10:06

    You can do something like this:

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/pws_streedandhousenodatas?$filter=_pws_streetandhousenumberid_value eq " + Xrm.Page.data.entity.getId(), true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var results = JSON.parse(this.response);
                for (var i = 0; i < results.value.length; i++) {
                    var pws_streedandhousenodataid = results.value[i]["pws_streedandhousenodataid"];
                }
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send();
    

    In this case the Xrm.Page.data.entity.getId() get you your current record id and you are looking all the lookups (that are in the sub-grid), you can also add some fields to select more info from them.

提交回复
热议问题