- 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:58 AM
Wrapping it in a function worked. Here is the final code:
scriptTest();
function scriptTest() {
var retVal;
if (gs.getUser().getRecord().getDisplayValue('department') == 'Product Management') {
retVal = true;
} else {
retVal = false;
}
return retVal;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2015 08:49 AM
can you try how you initially had it with just
if (gs.getUser().getRecord().getDisplayValue('department') == 'Product Management') {
return true;
} else {
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2015 09:00 AM
I had already tried that and I got the same error message but referencing line 2. I figured it out after cwilker10 responded above. I had to wrap the code in a function to get the return to work correctly. Here is my final working code:
scriptTest();
function scriptTest() {
var retVal;
if (gs.getUser().getRecord().getDisplayValue('department') == 'Product Management') {
retVal = true;
} else {
retVal = false;
}
return retVal;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2015 11:27 AM
If all you're interested in is if the user is in the Product Mgmt department, why'd you use the script ?
Why not use the department reference ?
Just askin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2016 06:41 AM
HEllo all, hello Timothy Harris
I don't know if this thread is already closed or not but sometimes it is better to use the global variable "answer" within the javascript into. Servicenow and set the 'answer = true / false' depeding on the logic