Check if a user is a SharePoint Administrator in JavaScript – SharePoint 2013.
Views (848)
Hi,
Had a requirement to check if user is a SharePoint Admin or not and accordingly hide few elements in the page. We used the below code in our custom master page
Sample Code
var currentUser;
function IsUserAdmin() {
clientContext = SP.ClientContext.get_current();
spWeb = clientContext.get_web();
currentUser = spWeb.get_currentUser();
clientContext.load(currentUser);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var isUserAdmin = currentUser.get_isSiteAdmin();
if (isUserAdmin) {
alert('Current User is Administrator');
} else {
alert('Current User is not an Administrator');
}
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
ExecuteOrDelayUntilScriptLoaded(GetCount, "sp.js");
Hope it helps ..
Filed under: SharePoint, SharePoint 2013 Tagged: SharePoint, SharePoint 2013
This was originally posted here.

Like
Report
*This post is locked for comments