This project has moved. For the latest updates, please go here.

SharePoint Hide a list field based on user group

Sep 20, 2013 at 7:31 PM
Edited Sep 20, 2013 at 8:30 PM
I have a list of columns which i need to display to certain set of users.I have followed this blog
and i am not able to achieve the use case.I am new to SPServices


The code mentioned below always gives an object

how to get the column name from the list that we want to hide.
      var IssueField = $("textarea [title=Issue]");
when i use the code mentioned below to hide i am getting the property is not supported on object.Please help me to resolve the issue.
     IssueField .parent().parent().parent().hide();       
Script on List NewForm.aspx

<script language="javascript" src="/jQueryLibraries/jquery-1.7.min.js" type="text/javascript"></script><script src="/jQueryLibraries/jquery.SPServices-0.7.0.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">

operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
   completefunc: function (xData, Status) {
   var xml = xData.responseXML.xml;
if($(xData.responseXML).find("Group[Name='PAGMembers']").length == 1)
     var feedbackField = $("input[title=Title]");
Sep 20, 2013 at 9:51 PM
It's hard to say where things are going wrong for you. However, you'll need to use a DOM inspector to find the right elements for your selectors.

Sep 25, 2013 at 2:48 PM
Edited Sep 25, 2013 at 5:56 PM
I am able to solve the issue and i am getting results.

I need one help.We have a production Protal where we are adding NT AUTHORITY\authenticated users so that all authenticated users can access the protal.

I use the below code to hide the columns based on User Group.

But the problem with the below mentioned code is let us say a user named A( NT AUTHORITY\authenticated users) is not part of ADG Members,ADG Owners and PAG Members then the GetGroupCollectionFromUser method is not going to return any results for me since user A is not in any one of the above mentioned groups.

I want to hide the columns for all the NT AUTHORITY\authenticated users.How to get the status from the completefunc: function(xData, Status) method.

So if the status is null or empty so that i can decide the user is a part of NT AUTHORITY\authenticated users.

Is any other way to overcome this issue.

<asp:Content ContentPlaceHolderId="PlaceHolderBodyAreaClass" runat="server">

<script type="text/javascript" src="http://ServerName/SiteCollectionDocuments/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" language="javascript" src="http://ServerName/SiteCollectionDocuments/js/jquery.SPServices-0.7.2.min.js"></script>

<script src="http://ServerName/SiteCollectionDocuments/jPoint-0.8/jPointLoader.js"></script>
<script src="http://ServerName/SiteCollectionDocuments/jPoint-0.8/jPoint-0.8.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready( function ()

                var isUserOnly = false; //User group member only
                var isModerator= false;
                var isAdmin=false;
                var isPAG=false;
                var MODERATORGROUP = "ADG Members"; // SPGroup named “Moderators”
                var ADMINGROUP = "ADG Owners";  // SPGroup named “Admin”
                var PAGGROUP = "PAG Members";  // SPGroup named “PAG Members”
                var NTAuthenticatedGROUP = "PAG Members";  // SPGroup named “PAG Members”
                var username;

                  operation: "GetGroupCollectionFromUser", //Calling GetGroupCollectionFromUser.asmx web service
                  userLoginName: $().SPServices.SPGetCurrentUser(), //Calling Current User
                  async: false,
          completefunc: function(xData, Status)

                                    $(xData.responseXML).find("Groups").each(function() //Retrieving the values from Group method of Web Service
                                        //Parsing through all the groups the current user belongs to


                    //Checking whether Current User belongs to Admin Group                          


                     if(($(this).attr("Name").toLowerCase() === ADMINGROUP.toLowerCase()))
                          isAdmin = true;
                    //Checking whether Current User belongs to Moderators Group
                      else if(($(this).attr("Name").toLowerCase() === MODERATORGROUP.toLowerCase()))

                    //Checking whether Current User belongs to P&G Group

                      else if(($(this).attr("Name").toLowerCase() === PAGGROUP.toLowerCase()))


                    //If Current User does not belong to Moderators or Admin, then definitely a normal user


              // Closing SPServices Method