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 ..
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

This works only in Edit mode. How can i make it working in published mode, too?
LikeLike
Wonderful beat ! I would like to apprentice at the same time as you amend your web site, how can i subscribe for a weblog website? The account helped me a acceptable deal. I were a little bit acquainted of this your broadcast provided brilliant transparent concept
LikeLike