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

Notifications

Announcements

No record found.

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

    <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

    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

    İ 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

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

  • Community Member Profile Picture
    on at

    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

    //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

    //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

    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

    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

    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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans