Why 2 journal entry records are created when work_notes are updated using before business rule

Viswanatha Red3
Mega Expert

Hi All,

For each note, I would like to add a hash tag. For achieving this, I have have created a before business rule on the task form and appending the work_notes with tag name

BEFORE business rule (Order 100)

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here
current.work_notes = current.work_notes+"\n#1234Viswa";
})(current, previous);

But when I enter a work note, I see two entries. One with the entered value, the other with the hastag. Is it possible to have only journal record entry ?

find_real_file.png

Regards

Viswa

7 REPLIES 7

Ibrahim-Ben Far
Tera Contributor

Hi @viswanath23,

modifying Journal Fields is a bit tricky and not easy to do as they act different to normal fields, that don't track a journal on their own. My suggestion is, that you do this kind of manipulation in an onSubmit Client Script. This doesn't cost much time (takes immediate effect) and you're working around the Journal Field Type exceptions...

Of course, this depends on what you want to do... as long as the hashtag generation doesn't require additional server-side available information (e.g. information from other Records in the system), a client-side script is completely fine for this jobs. If you need to do additional queries, e.g. in AJAX calls, there might be a slight delay before the actual submit if you are taking this direction.

For what kind of filtering would you use those hashtags? Maybe "normal" tags would do the same job for you?

 

Best Regards,

Ben

Ibrahim-Ben Far
Tera Contributor

There is also a Community Post about your problem with a more or less elegant solution...

https://community.servicenow.com/community?id=community_question&sys_id=1958cfaddb1cdbc01dcaf3231f96...

Harsh Vardhan
Giga Patron

can you try with below line 

 

current.work_notes.setJournalEntry('\n#1234Viswa');

Internally, setJournalEntry just calls setDisplayValue -- so they can be used synonymously.

Because Journal Fields are handled internally using an ArrayList and both functions actually call the add Function of the ArrayList, the underlaying problem is that this also results in a new record in sys_journal_field for each "setJournalEntry" call.

As for rendering purposes the created sys_journal_field records are reverse ordered (the most current displayed on top), using these functions also basically prepends the supplied text instead of appending it. This not only results in prepended text in the UI, but also in the audit and history, as these two depend on the "rendered" value...

So the safest way to do this, really is to do it on client-side...

 

Best Regards,

Ben