Hiding Form Sections Based on User Group

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2014 09:52 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2014 12:34 PM
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')

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2014 12:51 PM
so I need to put that on the BR? and am I putting it on the scratchpad as well??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2014 01:42 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2014 07:22 AM
I tried adding that, and the section is still visible to anyone in any group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2014 08:57 AM
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.