Get the Current Logged in User Using SharePoint 2013 CSOM

In the SharePoint 2013 environment, SP.UserProfiles JavaScript is used to get user profiles and user properties in custom solutions for SharePoint 2013 and apps for SharePoint.

There are various objects supported in the SP.userProfile namespace. They are given below.

  • HashTag
  • HashTagCollection
  • PeopleManager
  • PersonProperties
  • ProfileLoader
  • UserProfile
  • UserProfilePropertiesForUser

The following is sample code to get the current logged in user using the user profile in JavaScript.

<script src="/_layouts/15/SP.Runtime.js"></script>

<script src="/_layouts/15/SP.js"></script>

<script src="/_layouts/15/SP.UserProfiles.js"></script>




    // Ensure that the SP.UserProfiles.js file is loaded.

    SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');


var userProfileProperties;

function loadUserData(){

    //Get Current Context

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

    // People Manager Instance

    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    // current user

    userProfileProperties = peopleManager.getMyProperties()


    //Execute the Query.

    clientContext.executeQueryAsync(onSuccess, onFail);


function onSuccess() {



function onFail(sender, args) {

    alert("Error Occured: " + args.get_message());



Up Next
    Ebook Download
    View all
    View all