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

ShubhamGarg
Kilo Sage

Hello @TheKatherine ,

I have reviewed your code snippet and I want to suggest you few things.

You do not need to create a new field on any table (e.g. problem) to fetch the value of work_notes field. Work notes field itself is a journal type field which stores all its values for a given table record (irrespective of time period) in Journal Entry [sys_journal_field] table.

To solve above problem statement, there are two ways -

1. Either you write a business rule on problem table and fetch the latest entry of work_notes from journal entry table.

2. OR you fetch the value of work_notes field using these functions -

 

getJournalEntry(1) Gives you the most recent entry

getJournalEntry(-1) Gives you all entries

 

 

 

Let me know if it helps.

 

Mark this as Accepted Solution/Helpful if applicable.

 

Regards,

Shubham

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.

Based on GlideElement API documentation, I think it should be getJournalEntry(1) rather than getJournalEntry(0).

Thank you for the help.