SharePoint 2010 Client Object Model: Using the setTimeout() method

To use SharePoint 2010 client object model many .js files needed to be loaded. In this video example I was trying to use the get_current() method before all the appropriate .js files had been loaded. If the appropriate .js files are not loaded you might get the following error:

Uncaught TypeError: Cannot call method 'get_current' of undefined
Uncaught TypeError: Cannot call method ‘get_current’ of undefined

Retrieve a single item from a SharePoint 2010 list using the client object model

Let’s say or instance you wanted to retrieve a single item for a SharePoint 2010 list. If you can access the ID of the list item you can use the code below. In this code sample I used JavaScript.

function RetrieveSingleListItem(ListName, ItemId) {
  //Get the current client context
  clientContext = SP.ClientContext.get_current();
  var myList = clientContext.get_web().get_lists().getByTitle(ListName);
  listItems = myList.getItemById(ItemId);

  clientContext.executeQueryAsync(RetrieveSingleListItemSucceeded, RetrieveSingleListItemFailed);

  function RetrieveSingleListItemSucceeded(sender, args) {
value1 = listItems.get_item(‘Title’);

function RetrieveSingleListItemFailed(sender, args) {
  console.log(‘Request failed. ‘ + args.get_message() + ‘n’ + args.get_stackTrace());

Uncaught SyntaxError: Unexpected token = sp.js

While working with the SharePoint 2010 client object model, I got this error in in my Chrome Developer tools console window.

Uncaught SyntaxError: Unexpected token
Uncaught SyntaxError: Unexpected token

I did two things that might have cause this error.
1) I changed the domain password for my computer
2) I wanted to make the JavaScript in sp.js more readable. So I copied the entire sp.js file contents and used a JavaScript Beautifier

SharePoint 2010 Client Object Model: SP.UI.ModalDialog.OpenPopUpPage

SP.UI.ModalDialog.OpenPopUpPage(url, callback, width, height);


SP.UI.ModalDialog.OpenPopUpPage(“/Pages/Home.aspx”, null, 300, 300);

You can try this directly in the browser window using Firebug or Chrome tools (See video)

How to: Create a basic app for SharePoint by using “Napa” Office 365 Development Tools

Part 1:

Part 2:

Refer to this article for more details (Its actually an image of an article I and no longer find)

Download the app example here

SharePoint 2013: Create a list using JavaScript Client Object Model

<script type=”text/javascript”>

function createList(siteUrl) {
    var clientContext = new SP.ClientContext(siteUrl);
    var oWebsite = clientContext.get_web();
    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title(‘My Announcements List’);

    this.oList = oWebsite.get_lists().add(listCreationInfo);

        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)

function onQuerySucceeded() {
    var result = oList.get_title() + ‘ created.’;

function onQueryFailed(sender, args) {
    alert(‘Request failed. ‘ + args.get_message() + 
        ‘n’ + args.get_stackTrace());

Uncaught TypeError: Cannot read property ‘get_current’ of undefined

Client Object Model SP.ClientContext will not work if you are using minimal.master. If you are using minimal.master and want to use the client object model then you will need to add code that loads “sp.js” or you can just use v4.master.

Uncaught TypeError: Cannot read property 'get_current' of undefined
Chrome error
SP.ClientContext.get_current is null or not an object
IE error