
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2018 02:17 PM
Hello,
I have read a few ServiceNow articles and it appears you can get/pass Request Item variables to the Workflow Scratchpad OOB. Anyway having a problem or missing why I am not getting the value to the scratchpad.
So, on the sc_cat_item table, I created a new column called Manager Approval (u.manager.approval) [True/False]. This way on all our current catalog items a catalog admin can select if the Catalog item requires Manager Approval. In my workflow, I have the below IF condition to look to see if the Catalog item has the 'Manager Approval' checkbox set to True or False. But my workflow.scratchpad.u_manager_approval the variable is undefined. Am I missing something?
answer = ifScript();
var manApp = workflow.scratchpad.u_manager_approval;
//var manApp = current.variable_pool.u_manager_approval;
gs.info('manApp Value: ' + manApp); // returns 'undefined'
function ifScript() {
if (manApp == true) {
return 'yes';
}
return 'no';
}
gs.info('Answer Value: ' + answer); // returns 'no'
Here is an article that I referenced:
https://community.servicenow.com/community?id=community_question&sys_id=ddc013a9dbdcdbc01dcaf3231f9619f7
Thank you,
-Wesley
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2018 07:03 AM
I get it now, you can do this through filter condition, doesn't require scripting, like below, to check if manager field is true then if activity will return true else it will return false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2018 07:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2018 01:29 AM
Hi,
Fantastic explaination! thank you for that!
You have a field on catalog item itself named as Manager Approval. SO if this is true you want to go for approval and if false then skip this step.
So below is the code which you should place at start of your workflow in IF condition activity.
answer = Ifscript();
function Ifscript()
{
var cat = new GlideRecord('sc_cat_item');
cat.addQuery('sys_id',current.cat_item);
cat.query();
if(cat.next())
{
if(cat.u_manager_approval == 'true')
{
return 'yes';
}
else{
return 'no';
}
}
else
{
return 'no';
}
}
THis should be used in IF condition
THanks,
Ashutosh Munot

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2018 09:01 AM
Double Bingo! 🙂
I tested both ways. The script and condition builder both work great! Just with the script had to remove the ' ' (quotes) around == 'true', always have a hard time knowing/remembering when you need to use the ' ' (quotes).
So now with my Approval-User activity in the workflow, I am getting an error. I copied this script from another community string and it seems good. Do you see anything wrong? I also attached the error I am getting in the Workflow.
// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.
//
// For example:
// answer = [];
// answer.push('id1');
// answer.push('id2');
var approver = current.requested_by.manager.toString();
answer = [];
answer.push(approver);
Thanks!
-Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2018 10:31 AM
I do not see if requested_by is OOB field on sc_req_item table, if you have created this manually then it should be like,
answer = [];
var approver = current.u_requested_by.manager.toString();
answer.push(approver);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2018 10:42 AM
if requested_by custom field is on sc_request table then you have to use
answer = [];
var approver = current.request.u_requested_by.manager.toString();
answer.push(approver);