web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Check if a user is a ShareP...

Check if a user is a SharePoint Administrator in JavaScript – SharePoint 2013.

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

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.

Comments

*This post is locked for comments