SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 as follows

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.

share|improve this question

Users are not allowed to enumerate 'higher' permissions.

So have your script (which only has to run when administrators havechanged) dump the info into a public List (or formatted HTML file)

share|improve this answer
    
What about if I want to have this script be executed every time you visit the website? How would I go about creating a public list? – Russel B 8 hours ago
    
@RusselB, You can have the script execute each time, but it'll only work if the current user is an admin. A public list is simply a list, just make sure that everyone can view items in it. – wjervis 7 hours ago
    
As wjervis said... A List takes some extra administration, you have to clear existing Items, make your script (over)write a .txt file with the HTML you already have to a Library. Then use a Content Editor WebPart linked to that .txt file to display the HTML – Danny '365CSI' Engelman 6 hours ago

As site collection administrator options can be accessed only by site collection administrator, normal user cannot get this permissions.

One options i can think of is writing a site workflow and store this information in separate custom list, give read permissions to normal users on this list. Then you can use this list to query and display your data.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.