Need to get the previous comment field value of a journal input type field

sanga2
Tera Contributor
Hi all, I have a requirement where i need to check if the previous field value exist for a journal input type field 'comments'. How to check that using a business rule?
9 REPLIES 9

Hi, something this would check to see if there have been any comments added to the journal.

// get all journal entries and check that the result is not an empty sctring
if(current.comments.getJournalEntry(-1) != '') {
 gs.info('there are comments');   
} else {
   gs.info('there are no comments');   
}

HI Tony,

 

This is to check if there are current comments right? But I need to check if there exist some previous comments prior to the current comments.

 

Thanks.

Hi, 'current' is the current record IE the record running the BR
getJournalEntries checks the journal table for entries for the current record, IE previously saved entries for the record.

This is not the same as current\previous of a business rule, where previous is the last saved version of a fields value, and current is the value for the field that is being updated (not a 100% accurate definition, but perfect for this scenario).

Hi Tony,

 

I have used the below script to trigger the notification event when the comment field is updated the second time. Meaning, for the first comment it should not trigger the event, it should only trigger when the second comment is added on the journal input comment field. But it is not working as expected.

 

(function executeRule(current, previous /*null when async*/) {
if ( (current.comments.getJournalEntry(-2) != '')) {
gs.eventQueue("myeven", current, gs.getUserID(), gs.getUserName()); 
})(current, previous);
 
Can you tell why?

sanga2
Tera Contributor

Correction

 

(function executeRule(current, previous /*null when async*/) {
if ( (current.comments.getJournalEntry(-1) != '')) {
gs.eventQueue("myeven", current, gs.getUserID(), gs.getUserName()); 
})(current, previous);