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

You need to perform your check using "indexOf" as the result of the query could be 0 or more groups with a comma as delimiter.



You can try that within the background script.


try this:


var myGroups = gs.getUser().getMyGroups()


if (myGroups.indexOf('b85d44954a3623120004689b2d5dd60a') != -1) gs.print('true')


so I need to put that on the BR?   and am I putting it on the scratchpad as well??


No, you only have to incorporate "indexOf" in your client script.



Your code should then look like this:



function on Load() {


if (g_scratchpad.myGroups.indexOf('7efcb8956fa21100dd3253eabb3ee40c') != -1) {


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


}


}



Only adjust the sys_id and the variable on the g_scratchpad to match yours.


I tried adding that, and the section is still visible to anyone in any group.


Probably you need to review each single step your current implementation uses.


Start with the display business rule, check the outcome of the command you run there.


Next create a onLoad Client Script which will pop up an alert box (alert()) showing the content of the g_scratchpad variable.



If that is correct, work on the part finding a certain string (group sys_id) within the returned variable value and take it from there.