isMemberOf function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2013 03:34 AM
Sorry if the answer is obvious...
I am trying to set up some logic based on a person being a member of a group. From the wiki I understand that ...gs.getUser().isMemberOf...can be used for this. This is part of my code:
if (gs.getUser().isMemberOf('Service Desk')) {
// hide it
g_form.setVisible('u_selection', false);
} else {
// unhide it
g_form.setVisible('u_selection', true);
}
However I keep getting this error:
Problem at line 2 character 18: Unexpected token: if (gs.getUser().isMemberOf('Service Desk')) {
I have been playing around with the code and I have read through the wiki and the community site, but I fail to see what is amiss.
Marc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2013 05:43 AM
Thank you Mark, it is only available with elevated privileges. Should have thought about this myself.
The problem is that the script works, but it doesn't there where I need it. So I am afraid I have to expand.
What I try to should be simple. On a form I have a checkbox field that is now only visible for admins and I achieved this with a UI Policy and the following script:
function onCondition() {
if (!g_user.hasRole('admin')) {
// hide it
g_form.setVisible('u_selection', false);
} else {
// unhide it
g_form.setVisible('u_selection', true);
}
}
and this works.
Now I have to make this field visible to all members of the Service Desk. I can not select on Role, because there is no Service Desk role as such. So I am trying modify this existing script into:
function onCondition(){
if (!gs.getUser().isMemberOf('Service Desk')) {
// hide it
g_form.setVisible('u_selection', false);
} else {
// unhide it
g_form.setVisible('u_selection', true);
}
}
And that doesn't work.
Any suggestion to help me with this.
Thank you for looking into this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2013 05:57 AM
The problem is that you're trying to run server-side code (gs.getUser().isMemberOf) from the client (UI policies and client scripts). That code will never work because it's only available in server-side scripts.
If your field is always, consistently available only to service desk and admins, then it's probably better to set this security up with an ACL (which can leverage server-side scripts). If you can't do that for some reason, then you'll need to query to see if the user is a member of the assignment group. Doing that from the client is not a great idea because of the negative performance implications, but if you do have to do it from the client just try to issue an asynchronous call. ACL is the best method though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2013 06:03 AM
Thank you. I understand the problem and I will implement it with an ACL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2017 05:09 AM
Hi Marc,
As you are creating Client Script, you cannot use gs (GlideSystem) functions. You can create an ACL for that field with 'Read' operation and in script part you can write :
if (gs.getUser().isMemberOf('Service Desk'))
answer = true;
Please mark the solution correct if it resolved your problem.