Published on: 03/27/15 12:49 PM
Category:Javascript SharePoint 2013 Tags: active directory, javascript, SiteUsersHere is script of “How to get username from user id from Active directory”
[code language=”css”]
// get user name from id
function getUserFromId(userid) {
// var userid = _spPageContextInfo.userId;
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestHeaders = {
"accept": "application/json;odata=verbose"
};
$.ajax({
url: requestUri,
async: false,
contentType: "application/json;odata=verbose",
headers: requestHeaders,
success: onSuccess,
error: onError
});
function onSuccess(data, request) {
var Logg = data.d;
userLoginName = Logg.Title;
}
function onError(error) {
alert("error");
}
return userLoginName;
}
[/code]