• MS CRM 2011 在JScript中同步和异步使用REST Endpoint


    原创地址:http://www.cnblogs.com/jfzhu/admin/EditPosts.aspx?postid=2910622

    转载请注明出处

    在JScript中可以同步,也可以异步地使用REST Endpoint。以Retrieve为例,在下面的代码中,retrieveRecordsReq.open("GET", oDataPath + filter, false) 的第二个参数是false即为同步调用,如果为true即为异步调用。代码中其他部分同步与异步完全相同。

    if (typeof (ContactReadPaneLibrary) == "undefined") {
        ContactReadPaneLibrary = { __namespace: true };
    }
    
    
    ContactReadPaneLibrary = {
        Name: "ContactReadPaneLibrary",
        OnLoad: function () {
            if (parent.window.Xrm.Page.getAttribute("primarycontactid").getValue() != null && parent.window.Xrm.Page.getAttribute("primarycontactid").getValue().length > 0) {
                var primartycontact = parent.window.Xrm.Page.getAttribute("primarycontactid").getValue()[0];
                var contactid = primartycontact.id;
                var oDataPath = Xrm.Page.context.prependOrgName("/xrmservices/2011/organizationdata.svc");
                var filter = "/ContactSet(guid'" + contactid + "')?$select=Telephone1,FullName";
                var retrieveRecordsReq = new XMLHttpRequest();
                retrieveRecordsReq.open("GET", oDataPath + filter, false);
                retrieveRecordsReq.setRequestHeader("Accept", "application/json");
                retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                retrieveRecordsReq.onreadystatechange = function () {
                    ContactReadPaneLibrary.RetrieveContactCallBack(this);
                };
                retrieveRecordsReq.send();
            }
        },
        RetrieveContactCallBack: function (retrieveRecordsReq) {
            if (retrieveRecordsReq.readyState == 4 /* complete */) {
                if (retrieveRecordsReq.status == 200) {
                    //Success
                    //alert(retrieveRecordsReq.responseText);
                    if (retrieveRecordsReq.responseText) {
                        var retrievedRecord = JSON.parse(retrieveRecordsReq.responseText).d;
                        document.getElementById("TextFullname").value = retrievedRecord.FullName;
                        document.getElementById("TextBusinessPhone").value = retrievedRecord.Telephone1;
                    }
                }
                else {
                    alert("Error : " + retrieveRecordsReq.status + ": " +
                        retrieveRecordsReq.statusText + ": " +
                        JSON.parse(retrieveRecordsReq.responseText).error.message.value);
                }
            }
        }
    }

  • 相关阅读:
    Nginx 高级配置
    nginx安装和优化配置
    location语法介绍
    iptables
    通过 loganalyzer 展示数据库中的系统日志
    ubuntu_server16.04详细安装步骤
    内存控制mmap的原型和使用方法
    C语言中open函数read函数lseek函数是如何使用的
    gdb调试工具的基本使用
    C语言如何制作静态库
  • 原文地址:https://www.cnblogs.com/jfzhu/p/2910622.html
Copyright © 2020-2023  润新知