How to capture last work note and comment in Business rule on Task?

Kevin McGartlan
Tera Contributor

Hello, 

I would like to capture the last work note or comment on a task. My business would like to use these fields for reporting purposes. I currently have a business rule setup to capture those fields by using the code below. This is an after Business Rule on update/insert: 

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

current.u_last_comment = current.comment.getJournalEntry(1);
current.u_last_work_note = current.work_notes.getJournalEntry(1);
//current.u_entered_by_comments = current.comments.

})(current, previous);

I'm not sure what's wrong here. The u_last_comment and u_last_work_note were both setup initially as Strings, but I changed them to Journal just in case there was a variable mismatch. Still no luck. Any ideas on what to do here?

Also, I wanted to see if I can grab the "Entered By" and "When" of the last work note/comment as well. Is there any functions I can use to get that data as well? 

Thank you!

1 ACCEPTED SOLUTION

I'm glad I was able to assist you with getting that to work successfully.

When pulling the last journal entry...doesn't it say in that the name of the person and the date/time? It does for me.

But you could at the same time, use current.updated_by and place that somewhere as well which pulls who did it and then use current.sys_updated_on to get the date/time.

Please mark my other reply as Helpful and this one as Correct if this helps you solve it.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

11 REPLIES 11

Allen Andreas
Administrator
Administrator

Hi,

So is anything coming over at all?

Have you tried to do a gs.log(current.comment.getJournalEntry(1)); to see what it's saying?

Do you have any conditions listed that wouldn't make this run?

Is the BR actually active?

Have you tried to maybe do var lastComment = current.comment.getJournalEntry(1); and then do current.u_last_comment = lastComment; ?

 

Then entered by AND the date/time actually comes with it...which sort of sucks normally, but with your want, it should give you what you want. It'll be in the comment.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

I did try using gs.log on the two different fields, but it wasn't returning any values. Below is the log:

find_real_file.png

The BR is active. There are no conditions on when to run, except After and on insert and update. I also tried what you suggested here to switch the way I'm assigning variables. Still no luck. Any other ideas? I had thought maybe the business rule isn't activating, but it is as the log entries at least are executing. I had set the two fields to now be a String variable, but still no luck. 

That's great to hear about the entered by and Date/Time that comes with it. 

Thank you for your help!

Is there any sort of way to get that Entered By or When data though? We would like this data for reporting purposes again. 

Harsh Vardhan
Giga Patron

var notes = current.work_notes.getJournalEntry(-1);    // -1 for all the work notes value , 1 for latest work notes value

var notes = current.comments.getJournalEntry(-1);   

 

i believe you missed "s"