SP.User

Example

//create an object to act as a namespace
var myApp = {};
//Function that makes the client side call to the server
myApp.getUser = function(userId, onSuccess, onFailure) {
    myApp.clientContext = SP.ClientContext.get_current();
    myApp.user = myApp.clientContext.get_web().ensureUser(userId);
    myApp.clientContext.load(myApp.user);
    myApp.clientContext.executeQueryAsync(Function.createDelegate(this, onSuccess), Function.createDelegate(this, onFailure));
};
//If successful, this method is called
myApp.onSuccess = function(sender, args) {
    console.log("User Title: " + myApp.user.get_title());
    console.log("User Email: " + myApp.user.get_email());
    console.log("User id: " + myApp.user.get_id());
    console.log("User Login Name: " + myApp.user.get_loginName());
};
//If an error occurs this method is called
myApp.onFailure = function(sender, args) {
    if (args instanceof SP.ClientRequestFailedEventArgs) {
        var message = args.get_message();
        var code = args.get_errorCode();
        var details = args.get_errorDetails();
        var value = args.get_errorValue();
        var typeName = args.get_errorTypeName();
        var stack = args.get_stackTrace();
        var correlationId = args.get_errorTraceCorrelationId();
        alert('Error: ' + message + ".");
    } else {
        alert('Unexpected Error');
    }
};
//This method initates the process
function Test() {
    myApp.getUser("domain\\username", myApp.onSuccess, myApp.onFailure);
} 
$(document).ready(function () {
    ExecuteOrDelayUntilScriptLoaded(Test, "SP.js");
});

 

Available Methods

NameDescription
checkUninitializedPropertyInternal use
constructor 
customFromJson 
fromJson 
get_context 
get_emailReturns email address
get_groupsReturns an SP.GroupCollection
get_idReturns an int which is the Id of the user
get_isHiddenInUI 
get_isSiteAdminReturns true or false of user is Site Admin.
get_loginNameReturns user login name, which may be claims encoded.
get_objectDataInternal use
get_objectVersionInternal use
get_pathInternal use
get_principalTypeReturns Principal Type. 1 is Person.
get_serverObjectIsNullInternal
get_titleReturn title
get_typedObject Internal
get_userIdReturns SP.UserIdInfo object
initNonPropertiesFromJsonInternal
initPropertiesFromJsonInternal
isObjectPropertyInstantiatedInternal
isPropertyAvailableInternal
loadExpandoFieldsInternal
refreshLoad 
removeFromParentCollection 
retrieve 
set_emailSet email address
set_isSiteAdminSet IsSiteAdmin boolen
set_objectVersion 
set_titleSet title
updateMark object requires update .
updateClientObjectPropertyTypeInternal

 

 

CodeMonkey Software is a division of JCHMedia www.jchmedia.com