Hide SharePoint list columns based on user permissions

This SharePoint tutorial explains, hide sharepoint list columns based on user permissions using JavaScript. As we know Microsoft provided a powerful feature in SharePoint called Permission and group, we can easily manage our SharePoint site by using Out of box Permission and groups.

As we know Microsoft didn’t provide any out of box permission feature for list columns, so we will write a small piece of JavaScript code that will hide SharePoint online list columns based on user permissions.

Hide SharePoint list columns based on user permissions

The below are the steps to set permission to List column based on user groups.

In the below example, we will see how we can hide the Name list column from the form using JavaScript and SPServices code.

Step 1: Login to your SharePoint site and create a list as below image.

hide sharepoint list columns based on user permissions javascript
hide sharepoint list columns based on user permissions javascript

Step 2: The below is the code to hide your custom column for specific groups of user.

<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
 
<script type="text/javascript">
$(document).ready(function() {
 $().SPServices({
  operation: "GetGroupCollectionFromUser",
  userLoginName: $().SPServices.SPGetCurrentUser(),
  async: false,
  completefunc: function(xData, Status) {
  var xml = xData.responseXML.xml;
    if (xml.search('DHL Visitors') == -1)
     {                         
           $("select[title=Name]").parent().parent().parent().hide();          
       }  
    }
 });
});
</script>

Step 3: Next go to the NewForm.aspx and EditForm.aspx page -> Add a Script Editor WebPart in the both page. Next, add the below code inside it. When Visitors will login to the list they can’t see the specific Name field in both pages.

hide sharepoint list columns based on user permissions
hide sharepoint list columns based on user permissions

You may like following SharePoint customization tutorials:

Hope this SharePoint tutorial helps to hide SharePoint online list columns based on user permissions using JavaScript code.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

  • Hi Rajkiran, thanks for sharing this.

    Where do you apply this code to hide the column? Is it in view formatting?

    I am looking to hide certain columns, but want all users to add values to these columns in the form. Is this feasible?

    Kind regards,
    Jonas

  • What does the “$(“select[title=Name]”).parent().parent().parent().hide(); ” .parent().parent()…. do ??

  • >