web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to solve 'Context is not available' in javascript in crm 2015

(0) ShareShare
ReportReport
Posted on by 262

Hi, I want to get values from fetchxml using javascript in html web resource.I use crm 2015.The code block is in the attachment on picture. After the fetchxml, i try to get values with soap function. it gives me the error "Error: Contex is not available"I added the xrmservicetoolkit for crm 2015 and jquery and json files. What is the problem? How can ı solve this? Can anyone help me please?

var fetch = "<fetch version='1.0' mapping='logical'><entity name='quote'>";
  fetch += "<all-attributes />";
  fetch += "<filter type='and'>";
  fetch += "<condition attribute='new_anabayi' operator='eq' value='" + id + "' />";
  fetch += "<condition attribute='statuscode' operator='eq' value='1' />";
  fetch += "<condition attribute='customertypecode' operator='eq' value='7' />";
  fetch += "</filter></entity></fetch>";

var fetchData = XrmServiceToolkit.Soap.Fetch(fetch);

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

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

    Add  this line in head section of your html.

    Also, you can query your data using oData.

  • altun8tr Profile Picture
    262 on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    I added the line in head section. the error turns to "Error: XrmServiceToolkit.Fetch: No 'entity' node in the provided FetchXML.

    /.../WebResources/new_XrmServiceToolkit:2176"  It seems another problem occurred. As a result how can i get values from fetchxml using javascript.

  • altun8tr Profile Picture
    262 on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    İ saw a mistake in the fetchxml query . I fixed it. Now i get the same error again.

  • Yadnyesh Kuvalekar Profile Picture
    4,102 on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    Can you tell on which event your code is getting executed and where you have added the script?

  • Community Member Profile Picture
    on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    As i said you don't really need to use fetchXml to query your data. Build same request using oData (msdn.microsoft.com/.../gg334767%28v=crm.7%29.aspx;MSPPError=-2147217396). You can use tools such oData Query Designer  (dynamicsxrmtools.codeplex.com) for this.

  • altun8tr Profile Picture
    262 on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    //id from the previous page into this html web resource

    var id=getUrlParameter('Data');//geturlparameter is the function that ı et thr querystring parameter

    var fetch= "<fetch version='1.0' mapping='logical'><entity name='account'>";

              fetch += "<all-attributes />";

              fetch += "<filter type='and'>";

              fetch += "<condition attribute='new_anabayi' operator='eq' value='" + id + "' />";

              fetch += "<condition attribute='statuscode' operator='eq' value='1' />";

      fetch += "<condition attribute='customertypecode' operator='eq' value='7' />";

               fetch += "</filter></entity></fetch>";

    var fetchData = XrmServiceToolkit.Soap.Fetch(fetch);

    //This line i got the error. The error comes from the xrmservice toolkit library

    //Error: Context is not available.    /.../WebResources/new_XrmServiceToolkit:1348

    //I added this script in the html web source <script> part.

  • altun8tr Profile Picture
    262 on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    //id from the previous page into this html web resource

    var id=getUrlParameter('Data');//geturlparameter is the function that ı et thr querystring parameter

    var fetch= "<fetch version='1.0' mapping='logical'><entity name='account'>";

             fetch += "<all-attributes />";

             fetch += "<filter type='and'>";

             fetch += "<condition attribute='new_anabayi' operator='eq' value='" + id + "' />";

             fetch += "<condition attribute='statuscode' operator='eq' value='1' />";

     fetch += "<condition attribute='customertypecode' operator='eq' value='7' />";

              fetch += "</filter></entity></fetch>";

    var fetchData = XrmServiceToolkit.Soap.Fetch(fetch);

    //This line i got the error. The error comes from the xrmservice toolkit library

    //Error: Context is not available.    /.../WebResources/new_XrmServiceToolkit:1348

    //I added this script in the html web source <script> part.

  • Yadnyesh Kuvalekar Profile Picture
    4,102 on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    Kindly paste entire script part of your html web resource where you have added this line:

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

    Also, it is now recommended to use oData to retrieve data from CRM using JavaScript.

  • altun8tr Profile Picture
    262 on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    The adress that you send "(msdn.microsoft.com/.../gg334767%28v=crm.7%29.aspx;MSPPError=-2147217396)." is not working. I downloaded the package from (dynamicsxrmtools.codeplex.com) . How can i use it?

  • altun8tr Profile Picture
    262 on at
    RE: How to solve 'Context is not available' in javascript in crm 2015

    Here is my complete code:

    <html><head>

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

    <script type="text/javascript" src="hld-kay-crmtst/.../new_FetchUtil&quot;></script>

    <script type="text/javascript" src="hld-kay-crmtst/.../new_Json2&quot;></script>

    <script type="text/javascript" src="hld-kay-crmtst/.../new_Jquery&quot;></script>

    <script type="text/javascript" src="hld-kay-crmtst/.../new_XrmServiceToolkit&quot;></script>

    <script type="text/javascript" src="hld-kay-crmtst/.../new_sdkRest&quot;></script>

    <script>

     document.onreadystatechange = function () {

      if (document.readyState == "complete") {

      //id from the previous page into this html web resource

    var id=getUrlParameter('Data');//geturlparameter is the function that ı et thr querystring parameter

    var fetch= "<fetch version='1.0' mapping='logical'><entity name='account'>";

         fetch += "<all-attributes />";

         fetch += "<filter type='and'>";

         fetch += "<condition attribute='new_anabayi' operator='eq' value='" + id + "' />";

         fetch += "<condition attribute='statuscode' operator='eq' value='1' />";

     fetch += "<condition attribute='customertypecode' operator='eq' value='7' />";

         fetch += "</filter></entity></fetch>";

     alert('fetchi geçti');

    var fetchData = XrmServiceToolkit.Soap.Fetch(fetch);

       }

      }

    function getUrlParameter(name) {

       name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');

       var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');

       var results = regex.exec(location.search);

       return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));

    }

    </script>

    </head><body style="word-wrap: break-word;">

    <input type="checkbox" checked="checked" id="chkMagaza">

     <label id="lblMagaza"></label>

    </body></html>

    How can this code be written using oData?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans