- 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-19-2019 12:20 AM
Sorry for not being clear enough.
My variable name "approver" is a select box with all the choices that contains labels and names. They are purely texts without relating to the actual person. (screenshot below). There is another client script to display only the choices that appear in the select box based on certain conditions. Once requester has chosen the person from the dropdown, the approval is supposed to route to that person. All this tagging to the actual person, I am doing it under the Approval - User workflow > Advanced script.
What i am stuck is the script to point to the actual person. So for example based on screenshot, Head, OneStop@SAC is the title name of a person. How do i point in a way that, if requester select Head,OneStop@SAC, Mr XYZ in their form, in the approval workflow, it is routing to this person. I just need to call out this person in sys id table.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 12:25 AM
Hello Lisa,
have you try checking my script mentioned above? its similar to your requirement.
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-19-2019 03:24 AM
Hi Abhishek,
Thank you so much! It works exactly as what I wanted!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 12:35 AM
Hi Lisa,
The field mu_approver is a reference field . Top left of the image is the workflow , middle right of the image is the workings inside the approval user object (in the workflow) and bottom left of the image is the catalog item with the variable that is used in the workflow.
find below attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 12:39 AM
Hi Lisa,
Go through below link
if your query has resolved please mark the answer correct or helpful