- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2015 08:12 AM
I am trying to use an advanced script for User Criteria. On the wiki the only documentation says that the script field is "A script to define any additional criteria, and return true or false. This field is available only if Advanced is selected."
There is no example provided. I can't figure out how to reference the user record. For example, if I want to say all users who are active. How would I do this? I know the basic logic, but am unsure of how to reference the user record in the script.
Example logic:
if (currentUserRecord.active == true) {
return true;
} else {
return false;
}
Any help would be appreciated.
Thanks,
Tim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2015 08:18 AM
take a look at this page http://www.servicenowguru.com/scripting/user-object-cheat-sheet/
gs.getUser().getRecord().getValue('active') == true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2015 08:18 AM
take a look at this page http://www.servicenowguru.com/scripting/user-object-cheat-sheet/
gs.getUser().getRecord().getValue('active') == true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2015 08:21 AM
Thanks, let me try it real quick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2015 08:39 AM
So... I am getting the following error which is not allowing me to save: JavaScript parse error at line (7) column (6) problem = invalid return
Here is my code:
var answer;
if (gs.getUser().getRecord().getDisplayValue('department') == 'Product Management') {
answer = true;
} else {
answer = false;
}
return answer;
If I click the "Syntax Check" button it gives me a "Syntax OK" message, but on save I get the error shown above. Any ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2015 08:47 AM
Since I can only comment on what you have here, are you within a function call for that return? Also, I'd stay away from "answer" as a variable name as it is a variable that is used throughout ServiceNow for various things. I usually use something like 'retVal' for things like this. In many places in the system(Transform Map Field Scripts come to mind) you set "answer" to the value you want to use or evaluate.