Posts Tagged ‘sp.js’

Getting the logged on user name using the client object model

February 19, 2013 Leave a comment

If you want to use the SharePoint 2010 client object model you can use the code below:

ExecuteOrDelayUntilScriptLoaded(getWebUserData, “sp.js“);

    var context = null;

    var web = null;

    var currentUser = null; 

        function getWebUserData() { 

        context = new SP.ClientContext.get_current();

        web = context.get_web();

        currentUser = web.get_currentUser();



        context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), 

             Function.createDelegate(this, this.onFailureMethod));


    function onSuccessMethod(sender, args) {

        var userObject = web.get_currentUser();

        var UserTitle = userObject.get_title();



    function onFailureMethod(sender, args) {

        alert(‘request failed ‘);


Here is a video and a simple way to test it.


SP.ClientContext.get_current is null or not an object

February 5, 2013 Leave a comment

One of the reasons you might be getting this error is because you are trying to use the client object model without the sp.js file being loaded.

Other post regarding errors you might be getting related to the client object model and sp.js

You might need the ExecuteOrDelayUntilScriptLoaded method

Uncaught TypeError: Cannot read property ‘get_current’ of undefined

SP.ClientContext.get_current is null or not an object

%d bloggers like this: