sys_journal_field.value - conditionally-returns null/undefined

taarik_rahaman
Tera Expert

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');

//var commentText = sys_journal_field.getDisplayValue();

//var commentText = sys_journal_field.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!

1 ACCEPTED SOLUTION

Community Alums
Not applicable

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


View solution in original post

13 REPLIES 13

Community Alums
Not applicable

Are you attempting to copy all of the journal entries from one record to another?


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!


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!


Hi Taarik,



Please configure activity log and select the journal fields which you want to see in the activity log


Thanks Rashmi.   I think the fields displayed is not the problem here.