
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 08:53 AM
Hi folks,
I replicated this on a customer's Istanbul instance as well as on my own Developer instance from within a Business Rule and running as a Background Script:
var current = new GlideRecord('sc_req_item'); |
//current.get('number', 'RITM0011547');
current.get('number', 'RITM0010001');
var sys_journal_field = new GlideRecord('sys_journal_field');
sys_journal_field.addQuery('name', 'task'); | |
sys_journal_field.addQuery('element_id', current.sys_id); | |
sys_journal_field.addQuery('element', 'comments'); | |
sys_journal_field.addQuery('sys_created_by', gs.getUserName()); | |
sys_journal_field.orderByDesc('sys_created_on'); | |
sys_journal_field.query(); |
var commentText = sys_journal_field.value;
//var commentText = sys_journal_field.getValue('value'); | |||||||
|
if(sys_journal_field.next()) {
gs.print('Comment: ' + sys_journal_field.value, 'RITM comment BizRule'); | |
gs.print('Formatted Comment: ' + commentText, 'RITM comment BizRule'); |
}
The text in green shows my comment, whereas the text in red shows "undefined" or "null" depending on how I tried to set the commentText variable.
Anyone run into this before? Any ideas?
Thank you!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 10:18 AM
I just want to make sure I understand the requirements:
Instead of the BR firing an event, which triggers a notification, you want the comment to be added to the catalog tasks beneath the RITM? Or do you want to do both?
I would probably leave the BR as is, and create a new one which will copy the comments from the RITM down to each sc_task beneath it. Something like this:
Table: sc_req_item
when: after
filter conditions: active is true and additional comments changes
script conditions: gs.getUserID() == current.opened_by || gs.getUserID() == current.request.requested_for
(function executeRule(current, previous /*null when async*/) {
// Regex to strip header info from journal entries
var headerRE = /.+\n/;
// Get the latest comment in the record; strip out the header
var sComment = "Comment added from " + current.number + "\n\n";
sComment += current.comments.getJournalEntry(1).replace(headerRE, '');
var oTask = new GlideRecord("sc_task");
//oTask.addActiveQuery();
oTask.addQuery("request_item", current.sys_id);
oTask.addActiveQuery();
oTask.query();
while(oTask.next()) {
//gs.log("TM===>Updating " + oTask.number, "Q: Cascade Comments BR");
oTask.comments = sComment;
oTask.update();
}
})(current, previous);
Any comments added to the sc_task record should appear on the activity log.
Cheers,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 09:25 AM
Are you attempting to copy all of the journal entries from one record to another?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 09:30 AM
Hi Tim,
The "sc_req_item comment events" standard Business Rule simply sends Catalog Task assignees an e-mail when the parent RITM was updated.
I'm changing that to actually add a comment for each Catalog Task, rather than just send a notification.
...but I wonder if I know why you asked. 🙂 I could always do an insert() on the sys_journal_field table after changing the element ID!
Let me try that and see if it works!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 09:58 AM
Tim,
I'm successfully inserting the sys_journal_field record into the system (I can go to the table and see the record created) using the sys_id of the Catalog Task. However, it is not showing in the Activities section of the Catalog Task.
I'm going to research this a bit, but if you know the answer, please let me know.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 10:10 AM
Hi Taarik,
Please configure activity log and select the journal fields which you want to see in the activity log

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 10:59 AM
Thanks Rashmi. I think the fields displayed is not the problem here.