Hide SharePoint list columns based on user permissions

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 which will hide SharePoint online list columns based on user permissions.

SharePoint deveopment training course

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="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="http://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.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Rajkiran Swain

Rajkiran is currently working as a SharePoint Consultant in QATAR . Rajkiran having 6 + years of experience in Microsoft Technologies such as SharePoint 2019/2016/2013/2010, MOSS 2007,WSS 3.0, Migration, Asp.Net, C#.Net, Sql Server, Ajax, jQuery etc.He is C#Corner MVP (2 Times).

View all posts by Rajkiran Swain →