Friday, 2 November 2012

Hide Controls for particular sharepoint group using Jquery

This blog is to hide sharepoint contols, buttons, tables etc. for sharepoint group on page load.

Using CEWP we can achieve this simply refering some Jquery files and add CEWP in your page or list form and give your control id you want to hide and you can hide easily on Page Load.


Download Jquery files:
1. jquery.min.js
2. jquery-1.4.2.min.js
3. jquery.SPServices-0.5.4.min.js
4. jquery.SPServices-0.6.2.js

Add the script in your page either using CEWP or directly and refer above mentioned files as below:

<script src="site url/SiteAssets/jquery.min.js" type="text/javascript"></script><script src="/site url/SiteAssets/jquery-1.4.2.min.js" type="text/javascript"></script><script language="javascript" src="/site url/SiteAssets/jquery.SPServices-0.5.4.min.js" type="text/javascript"></script><script language="javascript" src="/site url/SiteAssets/jquery.SPServices-0.6.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status) {
        if($(xData.responseXML).find("Group[Name='Group Name']").length == 1)
         //alert('User in a group');
         document.getElementById("Ur control or button id").style.visibility="visible";
      document.getElementById("Ur control or button id").style.display="inline";
         //alert('User not in a group');
         document.getElementById("Ur control or button id").style.visibility="hidden";
         document.getElementById("Ur control or button id").style.display="none";
}); </script>



  1. Hi Ankur,

    Sorry for this dated reply maybe.
    But I've added you script and all the js refers to one of my wiki aspx pages, but whatever i try the script just doesn't seems to do anything.
    Am i missing something obvious here?



  2. Sorry for late reply

    Pls check the group name or Ur control or button id.

    Its a working script i used my times.

    u Can check by adding alert as well