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-11-2018 12:14 PM
It may work better to approach in a different way. If each manager has a 'signing amount' on their user record, it would be easy to determine if the amount populated on the RITM was too high for certain managers:
var userGr = new GlideRecord("sys_user");
userGr.addActiveQuery(); //filter inactive users
userGr.addNotNullQuery("u_amount"); // filter users with no 'amount' value
userGr.addQuery("u_amount", ">=", current.variables.cost); // filter managers who don't meet the approval amount requirements
Now, this may return multiple results, so how would you determine which manager to select? Or, would you populate the approvers list with multiple approvers if this was the case?
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 01:25 PM
Hi Tim,
Thanks for replying. I got it to work perfectly now using the following:
var gr = new GlideRecord('sys_user'); //Create variable called gr which is a GlideRecord object for the incident table
gr.addQuery('active',true); // Get active records
//Match the sys_id from the User table to the sys_id of the requested_for's manager
gr.addQuery('sys_id', current.request.requested_for.manager.sys_id.toString());
//Issue query to the db to get the relevant records
gr.query();
//Use a loop to compare the variable called cost on the requested item to the signing amount limits on the user table.
while (gr.next()) {
if (gr.u_amounts >= current.variables.cost) {
return 'yes';
}
else {
return 'no';
}
}
}