0

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?

3
  • Can you provide more details? Where is your custom action? In the Ribbon? What have you tried so far? Can you share the code you used to create your custom action / your custom action definition? Commented Feb 24, 2021 at 19:23
  • Which version of SharePoint? Is this SharePoint Online? Commented Feb 25, 2021 at 3:23
  • It's SharePoint 2016 on premise. Commented Feb 25, 2021 at 19:26

1 Answer 1

0

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:

1
  • you are being very presumptuous as to which version of SharePoint and which UX user1514428 is using in his/her environment. Linking to a 10 year old article written about a now unsupported version of SharePoint which may not apply if he/she is not using the Classic UX - that is not helpful. Give the user time to respond to the comments! Your code will not work if he/she is using the Modern UX. I would expect more from MSFT commenters. Commented Feb 25, 2021 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.