- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2015 11:53 AM
I'm trying to script an approval in a workflow on the request item table. Because the approving person changes based on another variable on the request we are simply using a variable. I've tried every way I could find in the wiki and the community, but every time the workflow hits this approval it just "skipped" and goes on to the next workflow step. Any help is greatly appreciated. Here is my script:
var answer = [];
var approver = new GlideRecord("sys_user");
approver.addQuery("user_name", current.variable_pool.who_approves);
approver.query();
while(approver.next()){
answer.push(approver);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2015 12:24 PM
- gs.log('David : Workflow variable print: ' + current.variable_pool.who_approves + ' ' + current.variable_pool.who_approves.getDisplayValue());
- var answer = [];
- var approver = new GlideRecord("sys_user");
- // approver.addQuery("user_name", current.variable_pool.who_approves); // It will return the sys id of the record variable referencing to
- approver.addQuery('sys_id',current.variable_pool.who_approves); // try this line or very next line to it.
- approver.addQuery('user_name',current.variable_pool.who_approves.getDisplayValue();
- approver.query();
- while(approver.next()){
- gs.log('David : Approver name is: ' + approver.user_name); // Always try to write down log statements to check the logic.
- answer.push(approver.sys_id);//corrected the last line as well.
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2015 11:56 AM
try creating the query without quotations or with single quotes around the field. That sometimes works for me:
approver.addQuery(user_name, current.variable_pool.who_approves);
or
approver.addQuery('user_name', current.variable_pool.who_approves);
Let me know if it works!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2015 12:04 PM
Also it seems like you are looking for who approves within the user name field. In this case, it might skip over this because this does not exist within the name field itself. Make sure you are setting up the GR correctly. For example, though I am not sure if this is your field name, you might want to try something like this:
approver.addQuery('variable_pool', current.who_approves);
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2015 12:20 PM
gs.log('David : Workflow variable print: ' + current.variable_pool.who_approves + ' ' + current.variable_pool.who_approves.getDisplayValue());
var answer = [];
var approver = new GlideRecord("sys_user");
// approver.addQuery("user_name", current.variable_pool.who_approves); // It will return the sys id of the record variable referencing to
approver.addQuery('sys_id',current.variable_pool.who_approves); // try this line or very next line to it.
approver.addQuery('user_name',current.variable_pool.who_approves.getDisplayValue();
approver.query();
while(approver.next()){
gs.log('David : Approver name is: ' + approver.user_name); // Always try to write down log statements to check the logic.
answer.push(approver);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2015 12:20 PM
We have a variable that the username of the person that needs to make the approval is input on. This variable (who_approves) is who we need to send the approval to. Once this approval is done the workflow proceeds to send our REST message to MS Orchestrator to trigger a Runbook. However, right now it is simply skipping the approval and sending the REST message. An approval is not even being generated.
Tried removing the quotes with no luck. I will note that if i hard code my sys_id into answer.push(<my sys_id>); it works. I'm guessing that the part of the script that grabs the sys_id from the username input in the variable is not working correctly.... but that is only my current guess.