How to insert a message into a journal entry/comment before it is saved?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2018 08:15 AM
For our case, we need to insert the users that are currently on the watch list at the time a comment is made to have a record of who was involved in a task when. Our end users do not access to service-now, instead they email to a general mailbox to initiate a task, since they do not access service-now they do not have visibility to the system messages that record the watch list activity. Also because there is several departments that utilize the service-now platform, this rule should only apply to our department and not be a global change. So far I have setup a before business rule that pulls the watch list and inserts into the current.comment but it appears this is still after the comment has been created because it creates two entries. My question is how do I add the watch list to what the user put in to the comments field so it is one entry?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2018 11:16 AM
(function executeRule(current, previous /*null when async*/)
{
// Add your code here
var list = current.watch_list.split(',');
var watchArr = [];
for (var i=0; i< list.length; i++)
{
var userElement = new GlideRecord("sys_user");
if (userElement.get('sys_id', list[i]))
{
watchArr.push(userElement.getDisplayValue());
}
else
{
watchArr.push(list[i]);
}
}
current.comments = 'Included in this conversation: ' + watchArr.join(', ') + "\n\n" + current.comments;
})(current, previous);
In addition to the screenshot I meant to paste the script that I am using.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2018 12:45 PM
Also we are using Istanbul.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2018 01:50 PM
I tried your code and got the same duplicate messages within the Activity Log. What I got to work is to populate the comments field using the setJournalEntry() method and leaving out the current.comments value. Here is your script you posted including the change:
(function executeRule(current, previous /*null when async*/) {
var list = current.watch_list.split(',');
var watchArr = [];
for (var i=0; i< list.length; i++) {
var userElement = new GlideRecord("sys_user");
if (userElement.get('sys_id', list[i])) {
watchArr.push(userElement.getDisplayValue());
} else {
watchArr.push(list[i]);
}
}
var cStr = 'Included in this conversation: ' + watchArr.join(', ');
current.comments.setJournalEntry(cStr);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2018 02:06 PM
Sorry, I guess I didn't give a very good illustration as to what I meant by duplicates, the script you provided does prevent the current.comment from being posted twice but it is still saving two comments instead of just one. One with the original current.comments and the second with the inserted text.
Here is an example from an outbound notification. Instead of it saving as two different journal entries I would like it save as just one.