Hiding Form Sections Based on User Group

allison_holt
Giga Expert

I am trying to hide a form section based on a users group, which is not listed on the form itself.

 

I tried the following client script and it's doesn't hide the tab.

 

function on Load(){

var me = g_user.userID();

if (me.isMemberOf('7efcb8956fa21100dd3253eabb3ee40c'){

var sections = g_form.getSections();

sections[3].style.display = 'block';

} else {

    sections[3].style.display = 'none';

    }

}

 

Any help as to what I can do to get this to work would be appreciated!

31 REPLIES 31

Hi,



I am using your suggested method as i want to show section[2] to only those users who are a part of "abc" group, but it is not working for me, Can you help?



Display BR:


(function executeRule(current, previous /*null when async*/) {



  gs.addInfoMessage("HI");


  g_scratchpad.groups = gs.getUser().isMemberOf('T&E Credit Card Team');


  gs.addInfoMessage("welcome");


})(current, previous);




CS:



function onLoad()


  {


  if (!g_form.isNewRecord())


  {


  var approvalstatus=g_form.getValue("u_approval_status");


  alert(approvalstatus);


  var sections = g_form.getSections();


  alert(sections);



  if((g_scratchpad.groups == false) && (approvalstatus == 'Approved')){


  alert("geet");



  sections[2].style.display = 'block';


  alert("bye");


  }


  }



  }


Hi,


You can hide sections using the following code and at times the index method may not work because if there are any mandatory fields in the section it will not hide.



Method 1:



var sections = g_form.getSections();


  sections[1].style.display = 'none';


  sections[2].style.display = 'none';


  sections[3].style.display = 'none';


  sections[4].style.display = 'none'



Method 2:



hiding tab and header separately.



document.getElementById('section_tab.dd37bcf1dbedfa000194d36fdf961927').style.display = 'none';




$$('.tab_caption_text').each(function(caption) {


      if(caption.innerHTML == 'Incident'){


              caption.up('.tab_header').hide();


      }


});



Thanks,


Vinitha.K


Hi Vinitha,



I want to hide it only for those who are not a part of "abc" group and approval status is approved of limit is finalized.


var person =   g_user.userID;


var ir = new GlideRecord('sys_user_grmember');


ir.addQuery('group', '50b8ef186fc62e00e40e0f1aea3ee456');//pass your group ID here.


ir.addQuery('user', person);


ir.query();


if(ir.next())


{


//hide section here


}


else{



}



Thanks,


Vinitha.K


tried this also,



function onLoad()


{


  if (!g_form.isNewRecord())


  {


  var sections = g_form.getSections();


  //var approvalstatus=g_form.getValue("u_approval_status");


  var person = g_user.getUserID();


  alert(person);


  var ir = new GlideRecord('sys_user_grmember');




  ir.addQuery('group', '64ca1638db6e3680130a50a4ce961922');


  alert('64ca1638db6e3680130a50a4ce961922');


  ir.addQuery('user', person);


  ir.query();


  if(ir.next()){


  g_form.setValue('u_comments', "hi shikha");


  sections[1].style.display = 'block';


  sections[2].style.display = 'block';



  }




Again not working.