SharePoint 2013 On-Premises.
I have a need to display Site Collection Administrators somewhere on the main page. To test this out, I have written a JavaScript for fetching user data of a website, doing isSiteAdmin
checks and displays if the information is correct.
The code is given below:
window.onload = function getUsers() { //script displays all Site Collection Administrators
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
var users = web.get_siteUsers(); //for adminUsers
var currentUser = web.get_currentUser(); // for currentUser
var allGroups = currentUser.get_groups(); // for currentUserGroup
//first query
clientContext.load(users);
clientContext.executeQueryAsync(adminUsers, executionFail);
var usList = []; // array for displaying users, since there can be more than one
function adminUsers(sender, args) {
for(var i = 0; i < users.get_count();i++){ // loop to gather all users
var user = users.getItemAtIndex(i);
var urlUser = user.get_loginName();
var urlUserSub = urlUser.substr(7);
var url = "test";
var name = user.get_title();
var check = user.get_isSiteAdmin();
if (check === true) // if user is SCA then add to the array
{
usList.push("<p style=\"margin-bottom:0px;\"><a href="+url+urlUserSub+">" + name +"</a></p>"); // some formatting for better visual display
}
}
document.getElementById('titleId').innerHTML = "Site Collection Administrators";
document.getElementById('addition').innerHTML = usList.join("");
} // end of adminUsers
Now the problem is that this code only works if you are Site Collection Administrator yourself.
How can I make this to work for other users? The idea is for all users to go on the main page of a given website and see who the Site Collection Administrator is, therefore everyone must be able to see it, not just me or any other site collection admin.
It appears to be a permission problem, but searching the web or checking any documentation gave me nothing. I concede the point that I have only been using SharePoint, or any SharePoint, for that matter, for only 3 weeks, so any help is appreciated.
UserInformationList
. Check my answer.