how to code it to add a variable 'plan' as 'Work Notes'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2026 02:14 AM
The command from the code below: addPlanToIncident () is to add a variable 'plan' to 'Additional Comments'. Does any one know how to code it to add a variable 'plan' as 'Work Notes'?
sn_itsm_aia.InvestigatingAndResolvingIncidentsUtil().addPlanToIncident(givenIncidentNumber, plan);
This code below is used to create a variable 'plan' and add it to the 'Additional Comments'.
(function(inputs) {
var plan = inputs['plan_to_add_array'];
var givenIncidentNumber = inputs['given_incident_number'];
if(typeof plan == "string") {
try{
plan = JSON.parse(plan);
}catch(ex){
gs.error("Error while parsing plan to add as comments: {0}", ex);
return new sn_itsm_aia.InvestigatingAndResolvingIncidentsUtil().addPlanToIncident(givenIncidentNumber, plan);
}
}
plan = plan.map(function(step, index) {
return step;
}).join('\n');
return new sn_itsm_aia.InvestigatingAndResolvingIncidentsUtil().addPlanToIncident(givenIncidentNumber, plan);
})(inputs);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2026 01:30 AM
Hi @SonnyY ,
In ServiceNow, the method addPlanToIncident() is a pre-built function within the InvestigatingAndResolvingIncidentsUtil Script Include. By default, this specific method is hardcoded to target the comments field (Additional Comments).
To switch this to work_notes, you generally have two options: check if a similar "Work Notes" method exists in that utility, or—more reliably—use the standard GlideRecord API to update the record directly.
Option 1: Using the Standard GlideRecord Approach
Since the out-of-the-box utility method is designed for comments, the most direct way to ensure the data goes to Work Notes is to write a small update script.
Replace your final return line with this logic:
(function(inputs) { var plan = inputs['plan_to_add_array']; var givenIncidentNumber = inputs['given_incident_number']; if (typeof plan == "string") { try { plan = JSON.parse(plan); } catch (ex) { gs.error("Error while parsing plan: {0}", ex); } } // Format the array into a newline-separated string var planString = (Array.isArray(plan)) ? plan.join('\n') : plan; // Direct Update to Work Notes var grIncident = new GlideRecord('incident'); if (grIncident.get('number', givenIncidentNumber)) { grIncident.work_notes = planString; grIncident.update(); return true; // Or return a success message } return false; })(inputs);
If this works, please mark it as helpful and please Accept my Solution..
Best Regards,
SIVASANKARI S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2026 02:52 AM
Hi, SIVASANKARI,
Many thanks for your swift response.
I've followed your instruction and it is still added into the 'Additional Comments'. Please see the screen shot. It would be easier if there's a command in the Util to add it straight to Work Notes. Any recommendation for the Syntax library?
Kind regards,
Sonny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2026 03:13 AM
Warning: Alert level: Warning.
Script uses GlideRecord. If directly processing input or returning information to the caller, use GlideRecordSecure instead.
I tried a few times. It's not working for me. When I used your code in the Script pop out window, it returned with a warning as above. Then I saved it and run. It seems fine, the test runs perfect.
However, the plan was added to the 'Additional Comments', not Work Note. When I return to the Script, I found out your code was not updated.
