2

I'm creating a custom button in the MS CRM ribbon that create a record in an entity, (i'm using odata), this button lunch a JavaScript function that use 'GetGlobalContext' method to get the context, im facing the below problem:

The value of the property 'GetGlobalContext' is null or undefined

here is my sample code :

//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) {
            }
        });
    }
}

any suggestions ??

1 Answer 1

3

it works fine now with var

var context = Xrm.Page.context;

instead of

var context = GetGlobalContext();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.