From 5918982d38eabc5b9fb0a42a899b6532fd613f13 Mon Sep 17 00:00:00 2001 From: Sachin Narayanasamy <132642563+SachinNarayanasamy@users.noreply.github.com> Date: Sun, 19 Oct 2025 13:11:33 +0530 Subject: [PATCH 1/2] Create 01README.md This ServiceNow Background Script allows you to add comments or work notes to a record on behalf of a specific user. --- .../Add Comments/01README.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Add Comments/01README.md diff --git a/Server-Side Components/Background Scripts/Add Comments/01README.md b/Server-Side Components/Background Scripts/Add Comments/01README.md new file mode 100644 index 0000000000..b9a54a6b19 --- /dev/null +++ b/Server-Side Components/Background Scripts/Add Comments/01README.md @@ -0,0 +1,44 @@ +ServiceNow Background Script – Add Comments on Behalf of a User +Overview + +This ServiceNow Background Script allows you to add comments or work notes to a record on behalf of a specific user. +Normally, when comments are added directly via scripts, they appear as the integration user. Using this script, the comment will show the actual user in the Activity Formatter. + +This is perfect for Hacktoberfest contributions, demos, or integration testing. + +Features + +Works directly in Scripts – Background in ServiceNow. + +Adds comments or work notes as a specified user. + +Can be used for the Incident table or easily adapted for other tables. + +Logs success or error messages in the Background Script output. + +How to Use + +Open Scripts – Background in your ServiceNow instance. + +Copy and paste the script. + +Update the input variables at the top of the script: + +var incidentSysId = 'INCIDENT_SYSID'; // sys_id of the record +var userName = 'john.doe'; // user_name to attribute the comment to +var commentText = 'Your comment here'; // comment content +var journalField = 'comments'; // 'comments' or 'work_notes' + + +Click Run Script. + +Check the Activity Formatter of the record to see the comment added under the correct user. + +Example +var incidentSysId = '1234567890abcdef'; +var userName = 'john.doe'; +var commentText = 'This is my Hacktoberfest comment!'; +var journalField = 'comments'; + + +After running, the comment will appear in the Incident’s activity log as if john.doe added it. From 8ec5d9bf206e6be5a2f6ce0d6f9d0bcaacb07644 Mon Sep 17 00:00:00 2001 From: Sachin Narayanasamy <132642563+SachinNarayanasamy@users.noreply.github.com> Date: Sun, 19 Oct 2025 13:12:21 +0530 Subject: [PATCH 2/2] Create Add_Comments_Script.js This ServiceNow Background Script allows you to add comments or work notes to a record on behalf of a specific user. --- .../Add Comments/Add_Comments_Script.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Add Comments/Add_Comments_Script.js diff --git a/Server-Side Components/Background Scripts/Add Comments/Add_Comments_Script.js b/Server-Side Components/Background Scripts/Add Comments/Add_Comments_Script.js new file mode 100644 index 0000000000..f46448867a --- /dev/null +++ b/Server-Side Components/Background Scripts/Add Comments/Add_Comments_Script.js @@ -0,0 +1,14 @@ +var incidentSysId = 'e9859dd4c39b2210ffd47205e401312d'; // sys_id of the incident + var userName = 'john.doe'; // user_name of the user adding the comment + var commentText = 'This is my Hacktoberfest comment via Background Script!'; // Comment text + var journalField = 'comments'; // Can be 'comments' or 'work_notes' + //var journalField='work_notes'; + + var incidentGR = new GlideRecord('incident'); + if (incidentGR.get(incidentSysId)) { + incidentGR[journalField].setJournalEntry(commentText, userName); + incidentGR.update(); + gs.info('Comment added successfully on Incident ' + incidentSysId + ' by ' + userName + '.'); + } else { + gs.error('Incident not found for sys_id: ' + incidentSysId); + }