- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 01:37 PM
Hello,
I would like to skip redundant approvals on RITMs.
All of our RITMs currently go to the requested for manager to approve and from there, there are typically additional approvals.
If one of those additional approvals is being routed to the person (typically the manager) who already approved, I would like to skip that. So whether it's auto setting that 2nd approval to "no longer required", or not generating the approval at all.
Since I would like this for all RITMs, would this be best solved by a Business Rule? Or specific scripting within the flow (we are using flow designer).
I found a post on ServiceNowguru.com, but it's pretty old and it recommend a business rule - so I followed the steps in this link and it did not work
Any specific help would be greatly appreciated!
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 05:34 AM
I think you have a mistake where you added the second line for the comments. Adding the second line requires you to have the curly brackets on the IF statement.
I also want to be sure that the business rule is a BEFORE with order 100 and only INSERT is selected (advanced view).
Another suggestion to figure out if everything works as desired is to add gs.log inside the code to understand why you are getting two records.
(function executeRule(current, previous /*null when async*/) {
// current.approver is the sys_id of the person that you will be evaluating on whether to create the necessary approval or not.
var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('state=approved^sysapproval='+current.sysapproval+'^approver='+current.approver); //all previuos approved approvals for the person on the RITM
gr.query();
if(gr.next()) {
current.state = 'approved';
current.comments = "Automatically approved based on a previous approval on the same record by the same user.";
}
})(current, previous);
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 02:04 PM
You may want to create a BEFORE 100 INSERT business rule on the sysapproval_approver table (individual approval table) to avoid "inserting" the approval record for that person. You may want to restrict this business rule to just the sc_req_item table as well.
They key is on the code that evaluates if there are approved approvals by the same person.
(function executeRule(current, previous /*null when async*/) {
// current.approver is the sys_id of the person that you will be evaluating on whether to create the necessary approval or not.
var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('state=approved^sysapproval='+current.sysapproval+'^approver='+current.approver); //all previuos approved approvals for the person on the RITM
gr.query();
if(gr.next())
current.setAbortAction(true);
})(current, previous);
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 07:02 PM
Hello,
Thank you! I think I am 99% there.. I had to add in a line of code to actually set the approval record to approved, otherwise the RITM state wouldn't update to "Approved". I have included the code below. This is now setting the RITM to approved, however, it's creating 2 approval records (both for the same person).. they are both being automatically approved with the note I added, however, I cannot figure out why there are 2 records. I've attached a screenshot of that. . so the first one is the first approval to the person that they manually approved. Then, the next 2 are the ones that are auto approved. There should only be 1. Any ideas on why it's creating 2 records? Thank you so much again.. I think this is going to be a great solution!
(function executeRule(current, previous /*null when async*/) {
// current.approver is the sys_id of the person that you will be evaluating on whether to create the necessary approval or not.
var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('state=approved^sysapproval='+current.sysapproval+'^approver='+current.approver); //all previuos approved approvals for the person on the RITM
gr.query();
if(gr.next())
current.state = 'approved';
current.comments = "Automatically approved based on a previous approval on the same record by the same user.";
})(current, previous);
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 05:34 AM
I think you have a mistake where you added the second line for the comments. Adding the second line requires you to have the curly brackets on the IF statement.
I also want to be sure that the business rule is a BEFORE with order 100 and only INSERT is selected (advanced view).
Another suggestion to figure out if everything works as desired is to add gs.log inside the code to understand why you are getting two records.
(function executeRule(current, previous /*null when async*/) {
// current.approver is the sys_id of the person that you will be evaluating on whether to create the necessary approval or not.
var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('state=approved^sysapproval='+current.sysapproval+'^approver='+current.approver); //all previuos approved approvals for the person on the RITM
gr.query();
if(gr.next()) {
current.state = 'approved';
current.comments = "Automatically approved based on a previous approval on the same record by the same user.";
}
})(current, previous);
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 07:15 AM
Thank you for all of the help - I do appreciate it. I updated the code to add the brackets as you indicated above and also confirmed it's 'before' , '100,' and just insert is selected.
The log isn't giving me any useful any information.
Thanks again for taking the time to help - I will continue to look at ways to remove the 2nd approval .