2

我正在 MS CRM 功能区中创建一个自定义按钮,该按钮在实体中创建记录,(我正在使用 odata),这个按钮午餐是一个 JavaScript 函数,它使用“GetGlobalContext”方法来获取上下文,我面临以下问题:

属性“GetGlobalContext”的值为 null 或未定义

这是我的示例代码:

//Parameters
var ODataPath;
var serverUrl;

//add the below script to the page DOM 
var imported = document.createElement('script');
imported.src = 'ClientGlobalContext.js.aspx';
document.getElementsByTagName('head')[0].appendChild(imported);


//On COnvert to case click
function OnConvertClick(message) {

    alert(Xrm.Page.getAttribute(message).getValue());
    var data = {
        subject: Xrm.Page.getAttribute(message).getValue()
    };

    CreateCaseOffer("incident", data);
}



//create case from an activity
function CreateCaseOffer(EntityName, data) {

    var context = GetGlobalContext(); //GetGlobalContext function exists in ClientGlobalContext.js.aspx
    serverUrl = location.protocol + "//" + location.hostname + ":" + location.port + "/" + context.getOrgUniqueName();
    ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

    var jsonCaseOffers = window.JSON.stringify(data);
    if (jsonCaseOffers != null) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: ODataPath + "/" + EntityName + "Set",
            data: jsonCaseOffers,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (data, textStatus, XmlHttpRequest) {
                $.each(data, function (k, v) {
                    alert(k + " - " + v);
                });
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
            }
        });
    }
}

有什么建议么 ??

4

1 回答 1

3

它现在可以正常使用 var

var context = Xrm.Page.context;

代替

var context = GetGlobalContext();
于 2012-12-07T13:01:14.110 回答