Update the Incident Work Notes that Change has been Rejected

Sakshi Lambat
Tera Contributor

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

1 ACCEPTED SOLUTION

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);

View solution in original post

16 REPLIES 16

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Sakshi Lambat 

 

A best link:

 

https://www.servicenow.com/community/itsm-forum/update-incident-worknotes-on-related-change-request-...

*************************************************************************************************************
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]

****************************************************************************************************************

Marcos Kassak
Kilo Sage
Kilo Sage

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!

Hi @Marcos Kassak 

Can I apply Business rule for change_request table ?

This link help you 

 

https://www.servicenow.com/community/itsm-forum/update-incident-worknotes-on-related-change-request-...

*************************************************************************************************************
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]

****************************************************************************************************************