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
Name | Description |
---|---|
checkUninitializedProperty | Internal use |
constructor | |
customFromJson | |
fromJson | |
get_context | |
get_email | Returns email address |
get_groups | Returns an SP.GroupCollection |
get_id | Returns an int which is the Id of the user |
get_isHiddenInUI | |
get_isSiteAdmin | Returns true or false of user is Site Admin. |
get_loginName | Returns user login name, which may be claims encoded. |
get_objectData | Internal use |
get_objectVersion | Internal use |
get_path | Internal use |
get_principalType | Returns Principal Type. 1 is Person. |
get_serverObjectIsNull | Internal |
get_title | Return title |
get_typedObject | Internal |
get_userId | Returns SP.UserIdInfo object |
initNonPropertiesFromJson | Internal |
initPropertiesFromJson | Internal |
isObjectPropertyInstantiated | Internal |
isPropertyAvailable | Internal |
loadExpandoFields | Internal |
refreshLoad | |
removeFromParentCollection | |
retrieve | |
set_email | Set email address |
set_isSiteAdmin | Set IsSiteAdmin boolen |
set_objectVersion | |
set_title | Set title |
update | Mark object requires update . |
updateClientObjectPropertyType | Internal |
CodeMonkey Software is a division of JCHMedia www.jchmedia.com