Blog

Show or hide column based on membership to SharePoint Group

I used SPServices library to hide or show list column to current user based on membership to the group.

Here are the steps:

  1. Create a permission group with desired users  in my case ‘Manager’
  2. Add sp services cdn or provide local reference and used below function.
  3. Replace the Group Name and Column to match your list.
$(document).ready(function() {
    $().SPServices({
        operation: "GetGroupCollectionFromUser",
        userLoginName: $().SPServices.SPGetCurrentUser(),
        async: false,
        completefunc: function(xData, Status) {
            // name of group

            if ($(xData.responseXML).find("Group[Name='Risk Manager']").length == 1) {
                //show column if user present in that group
                jQuery("select[id$='Overall_x0020_Status_6f27a9c6-3926-4889-a704-24466c675e73_$DropDownChoice']").show();

            } else {

                //hide column if user NOT present in that group
                jQuery("select[id$='Overall_x0020_Status_6f27a9c6-3926-4889-a704-24466c675e73_$DropDownChoice']").hide();
                //alert("hidden");
            }
        }
    });
});


Leave comments if you have any questions.

Leave a Reply

Your email address will not be published. Required fields are marked *