Script to hide SharePoint List Column for a particular SharePoint Group ID

  1. <script type=”text/javascript” src=”../_layouts/15/JS/jquery-1.11.2.min.js”></script>  
  2. <script type=”text/javascript”>  
  3. ExecuteOrDelayUntilScriptLoaded(getGroups, “sp.js”);  
  4. var user;  
  5. var visitorsGroup;  
  6. var userCollection;  
  7. var vGroupID = 6;      // Group ID for which the list column to be hidden  
  8.    
  9. function getGroups()  
  10. {  
  11.       var clientContext = new SP.ClientContext();  
  12.       var groupCollection = clientContext.get_site().get_rootWeb().get_siteGroups();  
  13.       visitorsGroup = groupCollection.getById(vGroupID);   
  14.       user = clientContext.get_web().get_currentUser();  
  15.       userCollection = visitorsGroup.get_users();  
  16.       clientContext.load(user);  
  17.       clientContext.load(visitorsGroup);  
  18.       clientContext.load(userCollection);  
  19.       clientContext.executeQueryAsync(Function.createDelegate(thisthis.onQuerySucceeded), Function.createDelegate(this,       this.onQueryFailed));  
  20. }  
  21. function onQuerySucceeded()  
  22. {  
  23.       for (var index = 0; index < userCollection.get_count(); index++) {  
  24.             if (userCollection.itemAt(index).get_loginName() === user.get_loginName())  
  25.             {  
  26.                   //alert(“User present in this group”);  
  27.                   //if column name is title  
  28.                   $(‘nobr:contains(“Title”)’).closest(‘tr’).hide();  
  29.                   return;  
  30.             }  
  31.       }  
  32.       // alert(“User notpresent in this group”);  
  33.       return ;  
  34. }  
  35. function onQueryFailed(sender, args) {  
  36.       //alert(“User notpresent in this group”);  
  37.       return ;  
  38. }  
  39. </script>