SharePoint – Use JQuery to hide columns based on a Users Group Membership


Hello everyone. Today I want to show you how you can use jQuery and SPServices to hide SharePoint columns based on a users group membership.

In a previous post I explained how you can use jQuery and SPServices to Auto-Fill fields. Please follow the instructions in this post but use the script below instead in your NewForm.aspx and/or EditForm.aspx pages.


<script type="text/javascript" src="/sites/test/Script/jquery.min.js"></script>
<script type="text/javascript" src="/sites/test/Script/jquery.SPServices.min.js"></script>

<script language="javascript" 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('SharePoint Group') != -1)
{

$('nobr:contains("TestColumn")').closest('tr').hide();

}
}
});
});
</script>

Replace “TestColumn” with the Name of your column you want to hide. And replace “SharePoint Group” with the Name of your SharePoint Group. If you configured everything correctly your column will be hidden for members of the SharePoint Group you defined in the script. (To hide a column for everyone except a specific group replace

if(xml.search('SharePoint Group') != -1)

with

if(xml.search('SharePoint Group') == -1)

)

That´s it. Now you are able to hide columns from specific user groups. I hope you liked my post. See you next time 🙂

And as always you can download my script from here.

Sources:

http://www.sharepointnadeem.com/2011/09/hide-sharepoint-list-field-based-on.html

http://sharepointroot.com/2011/09/23/sharepoint-2010-how-to-hide-blog-fields-using-jquery/

https://theezitguy.wordpress.com/2014/05/26/sharepoint-auto-fill-fields-using-jquery-and-spservices/

Advertisements
Tagged ,

One thought on “SharePoint – Use JQuery to hide columns based on a Users Group Membership

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: