How to get User Information List information using JSOM in SharePoint 2013/2016/online?

Hello SharePointers,

Below is the sharepoint JSOM code to user information list information for a logged in user.

ExecuteOrDelayUntilScriptLoaded(getUserProfile, “sp.js”);
function getUserProfileInformation(){
var userID= _spPageContextInfo.userId;
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
var userInfoList = web.get_siteUserInfoList();
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(“” + userID + “1”);
this.collListItem = userInfoList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args){
var item = collListItem.itemAt(0);
var MyuserName = item.get_fieldValues().UserName;
var MydisplayName= item.get_fieldValues().Title;
var Myemail= item.get_fieldValues().EMail;
var html=””;
if(MyuserName !=null){
html+=”<img src=’/_layouts/15/userphoto.aspx?size=S&username=” + MyuserName + “‘/>”;
}
if(displayName!=null){
html+=”

Name:”+ MydisplayName+”

“;
}
if(email!=null){
html+=”

Email: “+ Myemail+”

“;
}
var profileDiv = document.getElementById(“CurrentUserProfile”);
profileDiv.innerHTML = html;
}
function onQueryFailed(sender, args) {
//alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}
</script>
<div id=”CurrentUserProfile”>
<div>

Happy Sharepointing đŸ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *