locked
Calling a function in SDK.MetaData.js from an HTML web resource and I am getting the following error RRS feed

  • Question

  • Hi,

    I am trying to call a function in SDK.MetaData.js from an HTML web resource and I am getting the following error:

    JavaScript runtime error: Object doesn't support property or method 'getClientUrl'

    It looks like the problem is inside this function. Xrm is undefined.

                   function _Context() {

      var errorMessage = "Context is not available.";

      if (typeof GetGlobalContext != "undefined")

      { return GetGlobalContext(); }

      else {

       if (typeof Xrm != "undefined") {

        return Xrm.Page.context;

       }

       else

       { return new Error(errorMessage); }

      }

     };

    I have already added the 

        <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>

    in my web resource.

    Anybody ever faced this kind of a problem before?


    Sachith Chandrasiri

    Tuesday, March 15, 2016 1:54 AM

Answers

  • I have resolved this issue now with the help of my colleagues. 

    Instead of 

     <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>

    I should have used 

     <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>as there is no back slash character in my html web resource's name.


    Sachith Chandrasiri

    Tuesday, March 15, 2016 10:48 PM

All replies

  • Hi,

    what is the CRM version that you are using? because from CRM2011 UR 12 the new method is getServerUrl. you can use this javascript :

    var url ; if(Xrm.Page.context.getClientUrl)//Post UR 12 {     url = Xrm.Page.context.getClientUrl(); } else//Pre UR 12 {     url = Xrm.Page.context.getServerUrl(); }

    Thanks

    Alessandro


    Alessandro Graps

    Tuesday, March 15, 2016 11:41 AM
  • Tuesday, March 15, 2016 10:44 PM
  • I have resolved this issue now with the help of my colleagues. 

    Instead of 

     <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>

    I should have used 

     <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>as there is no back slash character in my html web resource's name.


    Sachith Chandrasiri

    Tuesday, March 15, 2016 10:48 PM