More fun with SharePoint and JavaScript

by dave Mon, June 20 2011 10:33

I was getting an odd error in a project in which the following line of JavaScript was throwing an error:

var ctx = new SP.ClientContext.get_current();

The error being thrown was: Microsoft JScript runtime error: Unable to get value of the property 'get_current': object is null or undefined

This was odd because it the debugger was telling me that “ClientContext” was undefined.  Huh?  That doesn’t make sense. 

Turns out the problem was the way I was calling the code.  The code above was in a function that I was calling from ExecuteOrDelayUntilScriptLoaded like this:

ExecuteOrDelayUntilScriptLoaded(myMethod(), "SP.js");

Do you see my mistake?  Yeah, I included the open and close parenthesis in the method call.  It should be:

ExecuteOrDelayUntilScriptLoaded(myMethod, "SP.js");

The error message certainly is a bit misleading…

Tags:

JavaScript | SharePoint 2010 | Development