Create work note after record is deleted

Miloslav1
Tera Contributor

Hello all, I would like to ask how I can create a work note about removed record. For example in my case I would like create a work note of removed change task in change request log if possible with the number of that deleted record. But I do not know if it is even possible to do such a thing.

 

I need it because customer is using third party tool to synchronize records between our Servicenow instance and their ITSM tool and they do not want to enable possibility of removal any value even in the initial(NEW) state of the record.

 

Anyway I will be glad for any links hint or confirmation, that this is not an option in Servicenow or it is not worth it to create such a thing.

 

Thanks in advance

1 ACCEPTED SOLUTION

Krushna R Birla
Kilo Sage

Hi @Miloslav1 

 

You need to write before-delete Business rule on change_task table to achieve this requirement. You can use below script for same,

 

 

(function executeRule(current, previous /*null when async*/ ) {

    var changeRequest = current.change_request.getRefRecord();

    if (changeRequest.isValidRecord()) {
        // Add a work note to the associated change request
        var workNoteMessage = "Change Task '" + current.number + "' has been deleted.";
        changeRequest.work_notes = workNoteMessage;
        changeRequest.update();
    }

})(current, previous);

 

 

KrushnaRBirla_0-1728919007219.png

 

This will definitely helps you to resolved your issue. Let me know in case you need anything else, you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

View solution in original post

4 REPLIES 4

Eshwar Reddy
Kilo Sage

Hi @Miloslav1 

Yes it is possible

Create BR on Change Task Table ( Before -> Delete)

In script Section get Change Request number associated to change Task and update Change Request 

var gr = new GlideRecord('change_request'); 
if (gr.get(current.change_request)) { 
gr.work_notes = 'Deleted Change Task ' + current.number.toString(); 
gr.update(); 
}

 

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution.

Thanks
Esh

 

Krushna R Birla
Kilo Sage

Hi @Miloslav1 

 

You need to write before-delete Business rule on change_task table to achieve this requirement. You can use below script for same,

 

 

(function executeRule(current, previous /*null when async*/ ) {

    var changeRequest = current.change_request.getRefRecord();

    if (changeRequest.isValidRecord()) {
        // Add a work note to the associated change request
        var workNoteMessage = "Change Task '" + current.number + "' has been deleted.";
        changeRequest.work_notes = workNoteMessage;
        changeRequest.update();
    }

})(current, previous);

 

 

KrushnaRBirla_0-1728919007219.png

 

This will definitely helps you to resolved your issue. Let me know in case you need anything else, you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

Omkar Mone
Mega Sage

You would need to write a before BR on the change_task table with the operation "delete". your code will look something like this - 

 

(function executeRule(current, previous /*null when async*/) {
    var changeRequest = new GlideRecord('change_request');
    if (changeRequest.get(current.change_request)) {
        changeRequest.work_notes = "The change task that got deleted is - " + current.number; // Verbiage can change.
        changeRequest.update();
    }

})(current, previous);

 

Miloslav1
Tera Contributor

Thank you very much all for quick help. It is working!