none
'TypeError' - Unable to get property 'load' of undefined or null reference for myCtx.load RRS feed

  • Question

  • I'm getting this error/exception:<o:p></o:p>

    'TypeError' -  Unable to get property 'load' of undefined or null reference for myCtx.load<o:p></o:p>

    from within a successful read handler as a result of this statement, in the parent method javascript hander that looks like this:<o:p></o:p>

      myCtx.executeQueryAsync(Function.createDelegate(this, function(){VerifyWebPartTitleAndUpdate(webPrtTitl,imgPath);}),

       function()

       {

        alert('Failure!');

       }

      );<o:p></o:p>

    everything up to this point in the execution seems to be functioning correctly as I step through it with the IE debugger. The error/exception is coming from this statement:

    myCtx.load(webPartDef);<o:p></o:p>

    in the following snippet of code (from the success handler):<o:p></o:p>

        if(webPartTitle == webPrtTitl)

        {

         webPartDef.openWebPart();

     

         var webPrtUpdtd = updateWebPartProperties(webPartDef, properties, imgPath);

         if(webPrtUpdtd)

         {

              webPartDef.saveWebPartChanges();

              webPartDef.closeWebPart();

              myCtx.load(webPartDef);

              myCtx.executeQueryAsync(function() 

              {

                  alert("'"+webPartTitle+"'WEB-PART PROPERTIES UPDATE SUCCESSFUL!");

              },
              function()
             {
                 alert("'" + webPartTitle + "' WEB-PART PROPERTIES UPDATE FAILED!"); 

             });
         }
         else
         {
             webPartDef.closeWebPart();
             alert("NO CHANGES MADE TO '" + webPrtTitl + "' WEB-PART.");
         }

    }<o:p></o:p>

    I suspect that when the success handler makes the method call shown here:<o:p></o:p>

    var webPrtUpdtd = updateWebPartProperties(webPartDef, properties, imgPath);<o:p></o:p>

    and then returns that perhaps the myCtx object originally set up in the parent to the success handler, somehow gets reset or is changed, as a result of calling the method in the line shown above. <o:p></o:p>

    If so then how do I successfully save it before the call is made and then reuse it after returning from the call above? I've tried several different variations, and so far no luck.<o:p></o:p>

    If that's not it then I don't understand how my context object which was previously good all of a sudden changed.<o:p></o:p>

    I'm Continuing to research and look into this issue.<o:p></o:p>

    Thanks for looking.<o:p></o:p>

    Henry <o:p></o:p>


    Tuesday, March 14, 2017 5:16 PM

Answers

  • I was previously losing the original context that I had setup at the highest level of my querying, so when I tried to reference it in lower level successful query handlers it kept coming up with undefined when I tried to use it. I think it was a mistake on my part, that I did figure out by just passing in my context variable to all query handler levels. It did have me stumped for a bit, but it seems to work now. So I hope I learned something and now I have another problem to post about a little farther down into the process. Hopefully be the last, before I get everything working.

    Thanks for looking. 

    Henry

    Tuesday, March 14, 2017 7:37 PM

All replies

  • Hi,

    Can you please provide proper format as i could not understand exact issue which you were facing. 

    And also, what order of JS you are following.

        $(document).ready(function () {

            // Get the URI decoded URLs. Try to use below format.

            hostweburl =            decodeURIComponent( getQueryStringParameter("SPHostUrl"));

            // Get the current app url

            appweburl = decodeURIComponent( getQueryStringParameter("SPAppWebUrl")

            );

            var scriptbase = hostweburl + "/_layouts/15/";

            $.getScript(scriptbase + "SP.Runtime.js",

                function () {

                    $.getScript(scriptbase + "SP.js",

                        function () { $.getScript(scriptbase + "SP.RequestExecutor.js", execOperation); }

                    );

                }

            );

        });

    Thanks

    Lalith

    -------------------------------------------------------------------------------------

    Please mark as answer, if my solution helps you.

    Tuesday, March 14, 2017 6:59 PM
  • I was previously losing the original context that I had setup at the highest level of my querying, so when I tried to reference it in lower level successful query handlers it kept coming up with undefined when I tried to use it. I think it was a mistake on my part, that I did figure out by just passing in my context variable to all query handler levels. It did have me stumped for a bit, but it seems to work now. So I hope I learned something and now I have another problem to post about a little farther down into the process. Hopefully be the last, before I get everything working.

    Thanks for looking. 

    Henry

    Tuesday, March 14, 2017 7:37 PM
  • Please don't ignore that marking as answer.
    Tuesday, March 14, 2017 7:56 PM