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

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

 

Hi @Sakshi Lambat 

 

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]

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

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.

Hi @Marcos Kassak 

SakshiLambat_1-1701959296275.png

I have added this conditions, and also your script but the incident worknotes are not getting updated

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