在前端JS中 call web api

前端写Web API 已经不是什么特别困难的问题,  我们可以使用 CRM REST Builder(https://github.com/jlattimer/CRMRESTBuilder)来生成想使用的 CRM REST Builder

 

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + parent.Xrm.Page.data.entity.getId().replace('{', '').replace('}', '') + ")?$select=accountid,address1_addressid", 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 result = JSON.parse(this.response);
            var accountid = result["accountid"];
            var address1_addressid = result["address1_addressid"];
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();

 

posted @ 2020-02-09 22:35  TheMiao  阅读(893)  评论(0编辑  收藏  举报