- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2022 08:35 PM
Hi everyone!
I was referring to this post to try to get the approvers to show up on the Service Portal ticket page.
https://community.servicenow.com/community?id=community_question&sys_id=5ff9520bdb518d10019ac2230596...
I was able to display the approvers.
However, if, for example, approval record B is created after approval record A is approved, the approvers for the previous record are still displayed and the approvers for the next record are added to the list.
In this case, when approval record B is created, we want only that approver to be displayed.
I have added code to the business rule to initialize the field for display to solve this problem, but it does not work.
How can I achieve my requirements?
Table Name: sysapproval_approver
When: After Insert
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.sysapproval);
gr.query();
// Show current approvers on glide_list field "u_current_approvers"
if (gr.u_current_approvers == '') {
if (gr.next()) {
gr.u_current_approvers += ',' + current.approver.toString();
}
// Initialize if there is a value in glide_list field "u_current_approvers"
} else {
gr.u_current_approvers = '';
if (gr.next()) {
gr.u_current_approvers += ',' + current.approver.toString();
}
}
gr.update();
})(current, previous);
Best Regards,
Kou
Solved! Go to Solution.
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 02:02 AM
Can you turn the logic around and create this BR on the sc_req_item table?
(function executeRule(current, previous /*null when async*/ ) {
current.u_current_approvers = '';
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval',current.getUniqueValue());
appr.addQuery('state','requested')
appr.query();
while(appr.next()){
current.u_current_approvers += appr.approver.toString() + ', ';
current.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 01:48 AM
That's strange because you are querying only 'requested' approvals. You should not get any 'no longer required' there, because that's also a state on the approval record. What is the trigger on your BR? Can you make make it 'approval = requested' it it's not already?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 02:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 10:33 PM
The BR now runs after you update the RITM. Can you make it on display? Because if you have a flow creating a first and second approval, your RITM isn't going to update. It stays on awaiting approval.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 07:44 PM
You are right!
My requirement was achieved by making the BR trigger asynchronous or before the update.
Thank you for your kindness and patience!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 10:31 PM
No problem. Glad it worked!