Skip to content

Commit 8ec5d9b

Browse files
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.
1 parent 5918982 commit 8ec5d9b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var incidentSysId = 'e9859dd4c39b2210ffd47205e401312d'; // sys_id of the incident
2+
var userName = 'john.doe'; // user_name of the user adding the comment
3+
var commentText = 'This is my Hacktoberfest comment via Background Script!'; // Comment text
4+
var journalField = 'comments'; // Can be 'comments' or 'work_notes'
5+
//var journalField='work_notes';
6+
7+
var incidentGR = new GlideRecord('incident');
8+
if (incidentGR.get(incidentSysId)) {
9+
incidentGR[journalField].setJournalEntry(commentText, userName);
10+
incidentGR.update();
11+
gs.info('Comment added successfully on Incident ' + incidentSysId + ' by ' + userName + '.');
12+
} else {
13+
gs.error('Incident not found for sys_id: ' + incidentSysId);
14+
}

0 commit comments

Comments
 (0)