Capture the Last Entry of WorkNotes on Problem using Business Rule - want data shown on report

TheKatherine
Tera Expert

Any help on Business Rules is greatly appreciated.

 

I would like to create a Business Rule to capture the last entry of worknotes from a Problem ticket using a Business Rule (on update or insert)and then be able to take the results and show it on a report.

 

In searching, I found the following code for a business rule ... is this accurate?

Do I need to create the new field (u_latestupdate) on the Problem table first? Would it be a string field?

 

business rule code:

(function executeRule(current, previous /*null when async*/ ) {
current.u_lastestupdate = current.work_notes.getJournalEntry(1);
current.setWorkflow(false);
current.update();
})(current, previous);

 

 

thank you

TheKatherine

1 ACCEPTED SOLUTION

Satishkumar B
Giga Sage
Giga Sage

Hi @TheKatherine 

Yes, a custom string field (u_latestupdate) is required to store the latest work note entry. Without this field, you won't have a place to save and display the most recent work note entry on the Problem ticket.

Create the field first, then use the Business Rule to populate it. Once set up, you can use the field for reporting purposes.

 

 

(function executeRule(current, previous /*null when async*/) {
    // Get the latest work note entry
    var latestEntry = current.work_notes.getJournalEntry(1);
    if (latestEntry) {
        current.u_latestupdate = latestEntry;
    }
})(current, previous);

 

 

 

Happy Learning

…………………………………………..
Mark it helpful 👍and Accept Solution !! If this helps you to understand.

View solution in original post

5 REPLIES 5

Slava Savitsky
Giga Sage

If you want just the last work note, then your approach is correct and the code also looks good, assuming that you are going to use an "after update" business rule. In case of a "before update" business rule, you don't need current.update() at all. A "before" business rule is preferable in such cases, but it may not work in your particular case because Work Notes is a journal field and is stored separately from the main record. But you can still give it a try.

 

Alternatively, you could simply add Work Notes as a column to your list report and do without any business rules.