Hide tab if SharePoint Group Member
Hi all,
is it possible to control via the SharePoint groups to hide a tab when I open a new form? My script does not work.
function IsCurrentUserMemberOfGroup(groupName, OnComplete) {
var context = new SP.ClientContext.get_current();
var currentWeb = context.get_web();
var currentUser = context.get_web().get_currentUser();
context.load(currentUser);
var allGroups = currentWeb.get_siteGroups();
context.load(allGroups);
var group = allGroups.getByName(groupName);
context.load(group);
var groupUsers = group.get_users();
context.load(groupUsers);
context.executeQueryAsync(
function(sender, args) {
var userInGroup = IsUserInGroup(currentUser,group);
OnComplete(userInGroup);
},
function OnFailure(sender, args) {
OnComplete(false);
}
);
function IsUserInGroup(user,group)
{
var groupUsers = group.get_users();
var userInGroup = false;
var groupUserEnumerator = groupUsers.getEnumerator();
while (groupUserEnumerator.moveNext()) {
var groupUser = groupUserEnumerator.get_current();
if (groupUser.get_id() == user.get_id()) {
userInGroup = true;
break;
}
}
return userInGroup;
}
}
IsCurrentUserMemberOfGroup('IT Process Change Request Members', function (isCurrentUserInGroup) {
if(isCurrentUserInGroup){
$('#fd_tabcontrol-0').tabs('option', 'disabled', [9]);
}
else
{
$('#fd_tabcontrol-0').tabs('option', 'enabled', [9]);
}
});
Best wishes
Tom
is it possible to control via the SharePoint groups to hide a tab when I open a new form? My script does not work.
function IsCurrentUserMemberOfGroup(groupName, OnComplete) {
var context = new SP.ClientContext.get_current();
var currentWeb = context.get_web();
var currentUser = context.get_web().get_currentUser();
context.load(currentUser);
var allGroups = currentWeb.get_siteGroups();
context.load(allGroups);
var group = allGroups.getByName(groupName);
context.load(group);
var groupUsers = group.get_users();
context.load(groupUsers);
context.executeQueryAsync(
function(sender, args) {
var userInGroup = IsUserInGroup(currentUser,group);
OnComplete(userInGroup);
},
function OnFailure(sender, args) {
OnComplete(false);
}
);
function IsUserInGroup(user,group)
{
var groupUsers = group.get_users();
var userInGroup = false;
var groupUserEnumerator = groupUsers.getEnumerator();
while (groupUserEnumerator.moveNext()) {
var groupUser = groupUserEnumerator.get_current();
if (groupUser.get_id() == user.get_id()) {
userInGroup = true;
break;
}
}
return userInGroup;
}
}
IsCurrentUserMemberOfGroup('IT Process Change Request Members', function (isCurrentUserInGroup) {
if(isCurrentUserInGroup){
$('#fd_tabcontrol-0').tabs('option', 'disabled', [9]);
}
else
{
$('#fd_tabcontrol-0').tabs('option', 'enabled', [9]);
}
});
Best wishes
Tom
Hello Tom,
Yes, it is possible. The code works on my form. Are you getting any errors in the browser console?
Check that you are using the valid user group name in the code.
And if you want to hide the disabled tab, add the following CSS directly to the form:
Yes, it is possible. The code works on my form. Are you getting any errors in the browser console?
Check that you are using the valid user group name in the code.
And if you want to hide the disabled tab, add the following CSS directly to the form:
Code: Select all
.ui-tabs .ui-state-disabled {
display: none; /* disabled tabs don't show up */
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 18 guests