Thursday, 24 July 2014

Unable to get property 'get_current' of undefined or null reference: Error in SharePoint App

Root Cause: You might have using wrong object creation in SharePoint App.
Ex: var ccontext = SP.ClientContext.get_current();
Solution:
Use below code.

var objContext = new SP.ClientobjContext.get_current();
var objWeb = objContext.get_web();
var objList = objWeb.get_lists().getByTitle('MyList');
var objListItemCreation = new SP.ListItemCreationInformation();
var objNewItem = objList.addItem(objListItemCreation);
objNewItem.set_item('Title', "Welcome");
objNewItem.update();
objContext.load(objNewItem);
objContext.executeQueryAsync(alert('Success'), alert('fail'));
view raw gistfile1.js hosted with ❤ by GitHub