Modifying a journal field before insert or update

dmartinc
Tera Expert

Hello,

I am trying to modify the comments (which is a journal / journaled field) inserted by a user into a task in some situations.
For that I have created a business rule of type "before" and "insert/update".
In the script of the business rule I do something similar to:


if (!gs.nil(current.comments)) {
   current.comments = current.comments + " additional text here";
}


The problem is that this does not modify the comment being inserted, but rather adds another comment. So if the user wrote "hello", we will have 2 comments:


hello additional text here
hello


I have searched the wiki and the forums and I have not found any easy way to do this. The only solution I can imagine is to delete the delete the older record from the sys_journal_field table but it would have to be done very well to not to delete the wrong comment.

Does anyone have any suggestion / ideas? 🙂

Thanks in advance,
David
9 REPLIES 9


dmartinc


Man, I wish I would've thought outside the box on that! Such a simple solution, IMO. Good call by your colleague. Thanks for posting your final solution.


Hi dmartinc

 

I tried same script what you have given, its working on sys_journal_field table (value is updating as expected), however its not reflecting in the task or incident table.

 

Is your script still working?

Dear @Kishore T K 

The thread started in 2011, almost 12 years ago! Time flies.

Unfortunately since then I have moved to another position. So I cannot tell you if the script is still working or not.

Good luck!

Have a look at knowledge article How to delete a Comment or a Work Note from a record to see what needs to be modified to successfully update a comment (update the journal entry, update the journal audit entry and rebuild the history set).

The title suggests it is a solution for entry deletion, but it is in fact for updates too.

russell_miller
Kilo Guru

An "On Submit" Client Script would do the trick.



e.g.



function onSubmit() {


      //Add to the entered comments


      var theComments = 'Additional Text Here\n-------------------\n' + g_form.getValue('comments');


      g_form.setValue('comments', theComments);


}



Saves playing with the sys_journal table.