How to query from most recent worknotes activities

Andre6
Mega Expert

Hi,

I'm doing a query from an IF statement workflow to get information from RTIM notes activities.

The script script is working but I would like to be able to query only the last activity (most recent).

The reason is in some cases, the workflow will need to loop back and will need to redo a query in the note activities and it will require to  see the lastest activity recorded.

Thanks in advance for your help

 

-----

answer = ifScript();

function ifScript() {

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

if (notes.toLowerCase().indexOf("please extend expiry date") > -1){
return 'yes';
}
if (notes.toLowerCase().indexOf("please deactivate/withdraw") > -1){
return 'no';
}
}

-----

2 ACCEPTED SOLUTIONS

Matthew Smith
Kilo Sage

getJournalEntry(Number mostRecent)

Returns either the most recent journal entry or all journal entries.
Parameters
Name Type Description
mostRecentNumberIf 1, returns the most recent entry. If -1, returns all journal entries.

 

 current.work_notes.getJournalEntry(-1); 

 current.work_notes.getJournalEntry(1);

View solution in original post

RaghavSh
Kilo Patron

You need to replace -1 with 1

var notes = current.work_notes.getJournalEntry(1);

 

-1 fetches all entries whereas 1 fetches the latest one.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023

View solution in original post

7 REPLIES 7

Sebas Di Loreto
Kilo Sage
Kilo Sage

Just put a 1 instead of -1. That will get you the last work_note from the journal entry.

-1 gets you all entries.

 

var notes = current.work_notes.getJournalEntry(1);


If I helped you with your case, please click the Thumb Icon and mark as Correct.


@Andre6 

Take a look at this great email script out of the box example (just add this to your instance prefix): /sys_script_email.do?sys_id=44f4bd7db7522300bc1308a9ee11a933

 

They get the last comment and split the array in all the elements (text, timestamp, user). The .shift() removes the first element (the text written) from the array since they want to use it to communicate the reject notes.


If I helped you with your case, please click the Thumb Icon and mark as Correct.


RaghavSh
Kilo Patron

You need to replace -1 with 1

var notes = current.work_notes.getJournalEntry(1);

 

-1 fetches all entries whereas 1 fetches the latest one.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023