- 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 05:48 AM
A best link:
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 05:59 AM - edited ‎12-07-2023 06:00 AM
Hi @Sakshi Lambat,
Lets breakdown into steps:
Identify Approval Rejection: Set a condition to check when an approval for a change request is rejected. This might involve a state change or a specific field update that denotes rejection.
Trigger Script: Create a Business Rule or script that executes when this rejection condition is met.
Update Incident Work Notes: Use a GlideRecord to find the associated incident and update its work notes field with the rejection message.
After configuring the business rule conditions (approval rejection), make sure to add this script:
(function executeRule(current, previous /* previous state */) {
// Check if the approval has been rejected
if (current.approval == 'rejected') { // Update 'approval' with the appropriate field or condition
var incidentGR = new GlideRecord('incident');
if (incidentGR.get('change_request', 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);
Ensure to adjust the conditions ('approval' field and 'change_request' field linking the incidents and changes) as per your instance's fields. You can also change the incident state if you want to, right below the work notes line.
Let me know if this works for you, or if you need any other help.
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 06:05 AM
Can I apply Business rule for change_request table ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 06:06 AM
This link help you
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]
****************************************************************************************************************