Workflow IF condition to compare field on sys_user table and variable on RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 09:37 AM
Hello, I am building a workflow that has ascending levels for manager approval based on their signing limit.
I am trying to use the IF condition to compare the signing limit (u_amount in sys_user) with a cost variable on an RITM before the approval moves to a higher manager. The signing limit must be where if the RITM variable cost is greater than the u_amount then the approval process moves to a higher manager. Here is what I have below but it obviously doesn't work. Any help would be appreciated.
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sys_user');
gr.addQuery('active',true);
gr.query();
// Use a while loop to find manager in sys_user and its limit
while((gr.user_name == request.requested_for_manager) && (gr.u_amounts >=current.variables.cost)){
mgr = gr.user_name;
limit = gr.u_amounts;
gs.log('LOOK HERE '+ mgr + ' ' + limit);
}
if (limit != ' ') {
return 'yes';
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 09:40 AM
Just looking at the code, is this part correct:
while((gr.user_name == request.requested_for_manager) && (gr.u_amounts >=current.variables.cost)){
Should it be:
while((gr.user_name == request.requested_for.manager) && (gr.u_amounts >=current.variables.cost)){
Unless 'request.requested_for_manager' is actually a field on table.
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 10:57 AM
Thanks for catching that error. Tim. It should be "requested_for.manager" Made the changes but the condition is still not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 11:08 AM
You may want to look at the Blog Article as a solution. Thinking you can have 1 If activity with multiple outputs to branch to the appropriate approval based on the amount comparison:
https://community.servicenow.com/community?id=community_blog&sys_id=d1fde22ddbd0dbc01dcaf3231f961912
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2018 12:12 PM
The script has been altered to the following in the IF condition
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sys_user');
gr.addQuery('active',true);
gr.addQuery('sys_id', request.requested_for.manager);
gr.query();
while (gr.next()) {
.
.
.
but the problem is with gr.addQuery('sys_id', request.requested_for.manager);
This line is to compare the name from the user table to the manager of the Requested for reference field in an RITIM. Does anyone know how I can get the sys_id of the manager? Thank you.