- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 02:06 PM
I'm trying to get certain options in the State field to hide if the current user is not a member of a group. The script I have so far is as follows:
function onLoad() {
var usr = g_user.getUserID();
var gate = g_form.getValue('u_field');
if (gate == 'true' && !usr.isMemberOf('GROUP')){
g_form.removeOption('state', '3'); //closed complete
g_form.removeOption('state', '4'); //closed incomplete
g_form.removeOption('state', '7'); //closed skipped
}
}
How do I get the opposite of 'isMemberOf'? I was thought it was an exclamation point (i.e. !usr.isMemberOf('group').
Thoughts?
Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 02:53 PM
Step 1: Create a display Business rule with script as. Place the below script between function templates in script body.
g_scratchpad.grp = gs.getUser().isMemberOf('PASS GROUP NAME HERE');
Now update the client script as
function onLoad() {
var usr = g_user.getUserID();
var gate = g_form.getValue('u_field');
if (gate == 'true' && !g_scratchpad.grp){
g_form.removeOption('state', '3'); //closed complete
g_form.removeOption('state', '4'); //closed incomplete
g_form.removeOption('state', '7'); //closed skipped
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 02:18 PM
Hello Karthik,
FYI: This script will not work at the client side and needs to be executed at server side via GlideAjax or set the scratchpad value to true or false at display BR and use it at client side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 02:21 PM
Yes Pradeep, I missed that Michael was trying on the client side

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 02:53 PM
Step 1: Create a display Business rule with script as. Place the below script between function templates in script body.
g_scratchpad.grp = gs.getUser().isMemberOf('PASS GROUP NAME HERE');
Now update the client script as
function onLoad() {
var usr = g_user.getUserID();
var gate = g_form.getValue('u_field');
if (gate == 'true' && !g_scratchpad.grp){
g_form.removeOption('state', '3'); //closed complete
g_form.removeOption('state', '4'); //closed incomplete
g_form.removeOption('state', '7'); //closed skipped
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2017 01:43 PM
How do I make it so that admins are not impacted (they see all states)?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2017 02:05 PM
Modify if condition as if (gate == 'true' && !g_scratchpad.grp && !g_user.hasRole('admin')){