- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 05:35 AM
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';
}
}
-----
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 05:45 AM
getJournalEntry(Number mostRecent)
mostRecent | Number | If 1, returns the most recent entry. If -1, returns all journal entries. |
current.work_notes.getJournalEntry(-1);
current.work_notes.getJournalEntry(1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 05:52 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 05:45 AM
getJournalEntry(Number mostRecent)
mostRecent | Number | If 1, returns the most recent entry. If -1, returns all journal entries. |
current.work_notes.getJournalEntry(-1);
current.work_notes.getJournalEntry(1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 05:50 AM
Hi @Andre6 ,
Can you give a try on below code :-
answer = ifScript();
function ifScript() {
var je = new GlideRecord('sys_journal_field');
je.addEncodedQuery('element=work_notes');
je.addQuery('element_id', current.sys_id.toString());
je.orderByDesc('sys_created_on');
je.setLimit(1);
je.query();
if (je.next()) {
if (je.value.toString().toLowerCase().indexOf("please extend expiry date") > -1) {
return 'yes';
} else if (je.value.toString().toLowerCase().indexOf("please deactivate/withdraw") > -1) {
return 'no';
}
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 06:23 AM
for a reason, the IF statement is always selecting No
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 06:27 AM
I would use the .getJournalEntry(1) command rather than gliding the whole journal table every time.
You will put unnecessary load on your system.
If I helped you with your case, please click the Thumb Icon and mark as Correct.