Мысли вслух…

How to determine a user’s SharePoint group using a JS

Автор: Мар.11.2012 Категория: Development, SharePoint

This is my first post in English, lets try.

Scenario: How to check user in group? Group contain specific user or not?

My Solution (I think it may be better, but)…

function SetRibbonDisplayStyle()
{
if (SPContext == null) {
SPContext = new SP.ClientContext.get_current();
}
web = SPContext.get_web();
this._currentUser = web.get_currentUser();
SPContext.load(this._currentUser);
groupCollection = web.get_siteGroups();
SPContext.load(groupCollection)
SPContext.executeQueryAsync(Function.createDelegate(this, this.onSuccessGroupGetting), Function.createDelegate(this, this.onQueryFailed));
}

function onSuccessGroupGetting(sender, args) {
var listEnumerator = groupCollection.getEnumerator();
while (listEnumerator.moveNext()) {
var item = listEnumerator.get_current();
var groupName = item.get_title();
if (groupName == 'USPS Content Editors') {
userCollection = item.get_users();
SPContext.load(userCollection);
SPContext.executeQueryAsync(Function.createDelegate(this, this.onSuccessUsersGetting), Function.createDelegate(this, this.onQueryFailed));
}
}
}

function onSuccessUsersGetting(sender, args) {
var listEnumerator = userCollection.getEnumerator();
while (listEnumerator.moveNext()) {
var item = listEnumerator.get_current();
if (item.get_loginName() == _currentUser.get_loginName()) {
$('#RibbonPlaceHolder').show();
}
}
}

The variables SPContext, groupCollection, userCollection is global.

:

Leave a Reply

:bad: :beer: :biggrin: :blink: :blush: :bomb: :confused: :cool: :crazy: :cry: :dont_know: :eek: :evil: :dance: :heart: :idea: :joke: :kiss: :lol: :mad: :music: :rose: :sad: :smile: :surprised: :tongue: :yahoo: :wall: :wink:
 

Поиск

Список друзей