- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 05:45 AM - edited ‎12-07-2023 05:45 AM
When the Change Request moves from Authorize to Scheduled state then Approval gets generated, if we reject the approval then the incident work notes must get updated that the 'Change has been rejected for the incident'. Please help me to figure out this
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 07:43 AM
There is definitely an extra } there, try this:
(function executeRule(current, previous /* previous state */) {
var incidentGR = new GlideRecord('incident');
if (incidentGR.get('rfc', current.sys_id)) {
// Update incident work notes
incidentGR.work_notes = 'Change request has been rejected: ' + current.number;
// Here you can also add a status change maybe
incidentGR.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 06:10 AM
Hi @Dr Atul G- LNG,
Yes...but I want the work notes of incident to be updated when the approval gets rejected for the Change request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 06:18 AM
The code is reference , just take this as base and make changes as per your requirement. Try hands and keep growing.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 06:13 AM
Yes, you should. Since the trigger will be a rejection on change_request and then the update on incident table will be made through the script.
Let me know if you have any other doubts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 06:29 AM
I have added this conditions, and also your script but the incident worknotes are not getting updated

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 06:34 AM
Hi @Sakshi Lambat,
Make sure to change it to After, then test the process again. Since you added the conditions to the BR, use this script instead:
(function executeRule(current, previous /* previous state */) {
var incidentGR = new GlideRecord('incident');
if (incidentGR.get('rfc', current.sys_id)) {
// Update incident work notes
incidentGR.work_notes = 'Change request has been rejected: ' + current.number;
// Here you can also add a status change maybe
incidentGR.update();
gs.addInfoMessage('Incident work notes updated for rejected change.');
}
}
})(current, previous);