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 06:01 PM
Hi @Jason116 ,
try this script
var caseNumbers = [
'CS0xxxxx',
'CS0xxxxx',
'CS01xxxx'
];
// Set field values
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.get('number',caseNumber)) {
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.work_notes = workNoteText;
gr.update();
// gr.addWorkNote(workNoteText); there is no addWorkNote method
// gr.update();
gs.print('Case ' + caseNumber + ' updated successfully.');
} else {
gs.print('Case ' + caseNumber + ' not found.');
}
}
there is no method as addWorkNote in the gliderecord
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 06:15 PM - edited 05-28-2025 06:21 PM
Hi @Jason116 ,
you can use No code data management job for this
create it against your table with condition number is one of your cases
and use field & values to set values
Auto updating system fields uncheck this (this is equivalent to autoSysFields(false) doesn't update the system fields)
Run business rules and engines uncheck this (this is equivalent to the setWorkflow(false) doesn't trigger notifications workflow engines etc)
once done click on continue UI action
once the record is saved click on the execute now UI action
easy to setup and use
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 07:37 PM
No did not work, still no work note added
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 06:31 AM
Hi @Jason116 ,
the worknote will be added with setWorkflow(false) and autoSysFields(false) it's just that it's not visible on the form because this not made to sy_history_set
someone who has never opened the form might see the work note when opened the record
just delete the sys_history_set entry of the case record for immediate effect and reload the form
use below script
var caseNumbers = [
'CS0xxxxx',
'CS0xxxxx',
'CS01xxxx'
];
// Set field values
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');
if (gr.get('number', caseNumber)) {
gr.setValue('state', '3');
gr.setValue('account', accountSysId);
gr.setValue('contact', contactSysId);
gr.setValue('assigned_to', assignedToSysId);
gr.setValue('category', categoryValue);
gr.work_notes = workNoteText;
gr.setWorkflow(false);
gr.autoSysFields(false);
gr.update();
///these lines delete the existing history set of current record so that the changes will be seen the form
var list = new GlideRecord("sys_history_set");
list.addEncodedQuery("id=" + gr.getUniqueValue() + "^table=sn_customerservice_case");
list.setLimit(10);
list.query();
list.deleteMultiple();
gs.info('Case ' + caseNumber + ' updated successfully.');
} else {
gs.info('Case ' + caseNumber + ' not found.');
}
}
@Roshnee Dash , @Robert H your thoughts on this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya