- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2022 10:41 PM
When a User Requested something example 'Apple iPhone 13' they have submitted the request. Now if they have any Approval or group Approval. if they have approval on Ritm for the request then it should automatically be added in the comments on the portal so that the end user can see how is the Approval for these Request example your request Approval is Abel Tuter should be added in the comments.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 06:49 AM
Hi @Sushant20
Try below :-
(function executeRule(current, previous /*null when async*/ ) { // Add your code here
var GroupApp = [];
var appr = new GlideRecord('sysapproval_approver');
appr.addEncodedQuery('state=requested^sysapproval=' + current.sys_id);
appr.query();
while (appr.next()) {
GroupApp.push(appr.getDisplayValue('approver')).toString();
}
current.setWorkflow(false);
current.autoSysFields(false);
if(GroupApp.length>0){
current.comments = 'Approvals For RITM :- \n' + GroupApp;
current.update();
}
})(current, previous);
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 12:12 AM
Try after insert business rule on sysapproval_approver table and utilize below script as per your need.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var grRITM = new GlideRecord('sc_req_item');
if(grRITM.get(current.document_id)){
grRITM.setValue('comments', 'Your request Approver is ' + current.approver.getDisplayValue() + '.');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 12:18 AM
Hi @Sushant20 ,
You can Create BR as below on RITM table
(function executeRule(current, previous /*null when async*/ ) { // Add your code here
var GroupApp = [];
var appr = new GlideRecord('sysapproval_approver');
appr.addEncodedQuery('state=requested^sysapproval=' + current.sys_id);
appr.query();
while (appr.next()) {
GroupApp.push(appr.approver).toString();
}
current.comments = 'Approvals For RITM :- \n' + GroupApp;
current.update();
})(current, previous);
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 05:52 AM
Thank you for your valuable time highly Appreciated! its giving the sys id of the Approver but we want name of the Approver additional comment .
2. Now its giving twice comments once from end user and once is system generated but we want only system generated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 05:58 AM
Hi @Sushant20
You can use below :-
(function executeRule(current, previous /*null when async*/ ) { // Add your code here
var GroupApp = [];
var appr = new GlideRecord('sysapproval_approver');
appr.addEncodedQuery('state=requested^sysapproval=' + current.sys_id);
appr.query();
while (appr.next()) {
GroupApp.push(appr.getDisplayValue('approver')).toString();
}
current.setWorkflow(false);
current.autoSysFields(false);
current.comments = 'Approvals For RITM :- \n' + GroupApp;
current.update();
})(current, previous);