I want to enable or disable custom Action button on following condition.
When user select list items in the list and if the user (created by) is particular user Group then I want to disable the Button.
How do I do this?
I want to enable or disable custom Action button on following condition.
When user select list items in the list and if the user (created by) is particular user Group then I want to disable the Button.
How do I do this?
Please run the following javascript script
// The below checks if the user exists in the group
function CheckUser(groupID, isInThisGroup) {
var context = SP.ClientContext.get_current();
//Go to parent site if use in a subsite!
var siteColl = context.get_site();
web = siteColl.get_rootWeb();
var groupCollection = web.get_siteGroups();
// Get the Group's ID
var _group = groupCollection.getById(groupID);
// Get all Users of the group
var users = _group.get_users();
context.load(_group);
context.load(users);
this._users = users;
// Get current user
this._currentUser = web.get_currentUser();
this._isInThisGroup = isInThisGroup;
context.load(this._currentUser);
context.executeQueryAsync(Function.createDelegate(this, this.CheckUserSucceeded), Function.createDelegate(this, this.failed));
}
//The below Checks if User is the member of the specified group
function CheckUserSucceeded() {
if (this._users.get_count() > 0) {
var _usersEnum = this._users.getEnumerator();
while (_usersEnum.moveNext()) {
var user = _usersEnum.get_current();
if (user.get_loginName() == this._currentUser.get_loginName()) {
//debugger;
arrIsInThisGroup[this._isInThisGroup] = true;
}
}
}
}
More information, please refer to this article: