Close Case Script - Add Work Notes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 05:36 PM
I am writing a background script to close out a large number of cases that have been stuck in the Resolved state. The script itself is fairly straightforward — it simply closes the cases and updates a few fields such as Account, Contact, Assigned To, and Category.
However, I’ve encountered an issue: I need to silence notifications as part of the process, but I also need to add a work note to each case. It seems that by suppressing notifications, journal field updates (like work notes) are also being suppressed, and as a result, the work notes are not being added. Everything else in the script is functioning correctly — it’s just the work notes that aren’t showing up
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 11:03 PM
Hello @Jason116 ,
Please try the following:
...
if (gr.next()) {
gr.setWorkflow(false);
gr.autoSysFields(false);
gr.setValue('state', '3');
gr.setValue('account', accountSysId);
gr.setValue('contact', contactSysId);
gr.setValue('assigned_to', assignedToSysId);
gr.setValue('category', categoryValue);
gr.update();
gr.autoSysFields(true); // required for work notes to get added
gr.work_notes = workNoteText; // there is no "addWorkNotes" method
gr.update();
gs.print('Case ' + caseNumber + ' updated successfully.');
}
...
The only notification that could be triggered would the one for work notes being added (if you have such a notification). This is unavoidable.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 11:31 PM
To ensure that work notes are added properly while still suppressing notifications, you should:
- Update the record with field changes first (with notifications suppressed).
- Then re-enable workflow/system fields before adding the work note.
Here’s how you can modify your script:
var caseNumbers = [
'CS0xxxxx',
'CS0xxxxx',
'CS01xxxx'
];
var accountSysId = '';
var contactSysId = '';
var assignedToSysId = '6';
var categoryValue = '39';
var workNoteText = "Add work note here........";
for (var i = 0; i < caseNumbers.length; i++) {
var caseNumber = caseNumbers[i];
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('number', caseNumber);
gr.query();
if (gr.next()) {
// Suppress notifications and auto fields for main update
gr.setWorkflow(false);
gr.autoSysFields(false);
gr.setValue('state', '3');
gr.setValue('account', accountSysId);
gr.setValue('contact', contactSysId);
gr.setValue('assigned_to', assignedToSysId);
gr.setValue('category', categoryValue);
gr.update();
// Re-fetch the record to ensure clean state
var grNote = new GlideRecord('sn_customerservice_case');
if (grNote.get(gr.sys_id)) {
// Enable workflow for journal field update
grNote.setWorkflow(true);
grNote.autoSysFields(true);
grNote.work_notes = workNoteText;
grNote.update();
}
gs.print('Case ' + caseNumber + ' updated successfully.');
} else {
gs.print('Case ' + caseNumber + ' not found.');
}
}
instead of providing the number inside array you can directly glide the record by using stateIsresolved something like that.
Stay awesome,
Roshnee Dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 12:35 PM
Hi @Jason116
If you found my response helpful, please mark it as correct and close the thread so others can benefit from it too.
Stay awesome,
Roshnee Dash