Copying values from journal fields

kalyani23
Tera Contributor

Hi,

we want to copy the values from journal field to string fields ,

work notes(journal input) to description and custom comments(journal input ) to short description.Only 1 field will be filled at a time,and other will be empty.so we have written the below code ,but when we are updating the journal fields the previous values are getting filled in the string fields. Also the string fields are not identifying which journal field to copy.

please provide solution .

if((current.work_notes!='')&&(current.custom_comments==''))
{
gs.addInfoMessage('c1:'+current.work_notes);
var grJournal = new GlideRecord('sys_journal_field');
grJournal.addQuery('element_id', current.sys_id);
grJournal.orderByDesc('sys_created_on');
grJournal.setLimit(1);
grJournal.query();
var i = 0;
if (grJournal.next()) {
i = i + 1;
//gs.addInfoMessage(i);

var comment = grJournal.getDisplayValue('value');
var id = current.document_id;
current.description=comment;
}
}
else if((current.work_notes=='')&&(current.custom_comments!=''))
{
gs.addInfoMessage('c1:'+current.custom_comments);
var grJournal1 = new GlideRecord('sys_journal_field');
grJournal1.addQuery('element_id', current.sys_id);
grJournal1.orderByDesc('sys_created_on');
grJournal1.setLimit(1);
grJournal1.query();
var j = 0;
if (grJournal1.next()) {
i = i + 1;
//gs.addInfoMessage(i);

var comment1 = grJournal1.getDisplayValue('value');
var id1 = current.document_id;
current.short_description=comment1;
}

current.update();
}

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

You should run this as a before Update Business Rule when one or the other journal fields changes to avoid the current.update().  You don't need to do a GlideRecord to get the most recent journal entry on the current record, just use something like this:

current.description = current.work_notes.getJournalEntry(1);