I'm on SP2013 in an O365 environment.
I am trying to pull some data from a list and render that data using the Google charts API. I am doing this in a content editor web part that points to an HTML page in the site's Site Assets library.
Using the following JavaScript, I get the 'Unable to get property 'get current' of undefined or null reference' error in the debugger.
function getItem(listTitle,itemId,success,error){
var context = SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(listTitle);
var listItem = list.getItemById(itemId);
context.load(listItem);
context.executeQueryAsync(
function() {
success(listItem);
},
error
);
}
var dxOrphan = getItem('ChartData', 1,
function(item){
var result = item.get_item('Topics');
},
function(sender,args){
console.log(args.get_message());
}
);
The reading I've done seems to indicate that this is a problem with sp.js loading after the getItem() function is called.
So I added the following line:
ExecuteOrDelayUntilScriptLoaded(getItem, "sp.js");
Which gets me a new error, this time in sp.js: "Unable to get property 'toUpperCase' of undefined or null reference."
I'm guessing that this is because the getItem () function is returning no data, but it's odd, because sp.js still seems to be loading afterwards -- that is, I always get the 'get current' error first, then the 'toUpperCase' error.
I feel like I'm close to getting this working, and have been Googling furiously for the past few hours trying to find a solution. If I should scrap this approach and try something else, I'm happy to hear that message as well.