I have a custom list and when the user open the list item Display form there is a custom ribbon. This ribbon should be enabled if the current user is a member of a particular Group. Here is the caml query i used

var id = JSRequest.QueryString["ID"];
if (contextKey == "ApproveRequest") {
    var condition = '<View>' + 
                        '<Query>' + 
                            '<Where>' + 
                                '<And>' + 
                                    '<Eq>' + 
                                        '<FieldRef Name=\"ID\"></FieldRef>' + 
                                        '<Value Type=\"Integer\">' + id + '</Value>' + 
                                    '</Eq>' + 
                                    '<Or>' + 
                                        '<Membership Type="SPGroup" ID="447">' + 
                                            '<FieldRef Name=\"Author\"/>' + 
                                        '</Membership>' + 
                                        '<Eq>' + 
                                            '<FieldRef Name= \"Author\"/>' + 
                                            '<Value Type="Integer"><UserID Type="Integer"/></Value>' + 
                                        '</Eq>' + 
                                    '</Or>' + 
                                '</And>' + 
                            '</Where>' + 
                        '</Query>' + 

but the above Code is not working.

1 Answer 1


You can use the code below to check if the current user is a member of a particular group, then show or hide the custom ribbon button.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
    isMember("Some Group Name").done(function(){
        if(data.d.results[0] != undefined){
            //show the custom ribbon 
            //hide the custom ribbon
function isMember(groupName){
    return $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('"+ groupName +"')/Users?$filter=Id eq " + _spPageContextInfo.userId,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose"}

Or use the JSOM code to achieve it.

<script type="text/javascript">
function IsCurrentUserWithContributePerms() 
  IsCurrentUserMemberOfGroup("Members", function (isCurrentUserInGroup) {
        // The current user is in the [Members] group

ExecuteOrDelayUntilScriptLoaded(IsCurrentUserWithContributePerms, 'SP.js');
function IsCurrentUserMemberOfGroup(groupName, OnComplete) {

        var context = new SP.ClientContext.get_current();
        var currentWeb = context.get_web();

        var currentUser = context.get_web().get_currentUser();

        var allGroups = currentWeb.get_siteGroups();

        var group = allGroups.getByName(groupName);

        var groupUsers = group.get_users();

                function(sender, args) {
                   var userInGroup = IsUserInGroup(currentUser,group);         
                function OnFailure(sender, args) {

        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;
            return userInGroup;

Or the article below for your reference.

Enable\Disable Ribbon button by Users Group SharePoint

Your Answer

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

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