- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 02:45 AM
Hi,
Sorry, I am new to scripting...
I have a selectbox field in my form which contains only names of individuals for the users to select. Whoever they select will be the approver whereby in the workflow, it will send to the correct person based on selection. This selectbox called approver does not tie to any user table and is just values containing names.
In my Approval workflow, I want to retrieve the values from the selectbox and from there, i will tie to user table so that it will call the actual person as the Approver. I am not sure if the below script I placed in "Additional approvers script" in my Approval workflow is correct:
Can anyone help please? Thank you
// 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.
//
answer = [];
var getUser = new GlideRecord('sys_user');
// gs.log("u_approver =" +u_approver);
if(current.variables.approver == 'head_onestop_sac')
{
getUser.addQuery('title', 'Head, One Stop @ SAC');
}
else if(current.variables.approver == 'director_admissions')
{
getUser.addQuery('title', 'Director');
getUser.addQuery('department', 'Office of Admissions');
}
answer.push(u_approver);
// answer.push('id2');
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 03:44 AM
Hello Lisa,
Your code should be like this:
// 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.
answer = [];
var getUser = new GlideRecord('sys_user');
if(current.variables.approver == 'head_onestop_sac')
{
getUser.addQuery('title', 'Head, One Stop @ SAC');
getUser.query();
while(getUser.next()){
gs.log(" First IF :user name:"+getUser.name);
answer.push(getUser.sys_id);
}
}
else if(current.variables.approver == 'director_admissions')
{
getUser.addQuery('title', 'Director');
getUser.addQuery('department', 'Office of Admissions');
getUser.query();
while(getUser.next()){
gs.log("ELSE IF:user name:"+getUser.name);
answer.push(getUser.sys_id);
}
}
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 02:50 AM
Hi Lisa,
Do you have full name of the user in the variable because based on that query will take place?
what is u_approver? is that the name of the variable which holds the full name of the user
also you are just querying based on department or title; what about the user which is available in the selectbox field
why you are having query of title and department if you want to send approval to that user directly?
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 02:54 AM
What is u_approver here? Where it is defined
Thanks,
Abhishek
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 03:44 AM
Hello Lisa,
Your code should be like this:
// 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.
answer = [];
var getUser = new GlideRecord('sys_user');
if(current.variables.approver == 'head_onestop_sac')
{
getUser.addQuery('title', 'Head, One Stop @ SAC');
getUser.query();
while(getUser.next()){
gs.log(" First IF :user name:"+getUser.name);
answer.push(getUser.sys_id);
}
}
else if(current.variables.approver == 'director_admissions')
{
getUser.addQuery('title', 'Director');
getUser.addQuery('department', 'Office of Admissions');
getUser.query();
while(getUser.next()){
gs.log("ELSE IF:user name:"+getUser.name);
answer.push(getUser.sys_id);
}
}
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 04:28 AM
HI,
What is the connection or common factory between this variable and User table field
Thanks,
Ashutosh