Differences between getJournalEntry(1) and getJournalEntry(-1)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 05:41 AM
Hi ,
Can any one explain differences between getJournalEntry(1) and getJournalEntry(-1).
"In salesforce when I comment it then without refreshing the pages details reflect on the sevicenow.
But when comments on the servicenow ,It need to referesh the page in servicenow as well as sales force side also."
Can any one explain the logic or analysis.pradeepksharmabawiskargoranlundqvistdeepak.ingalekalaieric.schroederctomasi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 05:47 AM
getJournalEntry(1) gets the latest entry.
getJournalEntry(-1) gets all entries.
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=SGE-getJournalEntry_N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2021 08:43 AM
Hi Tomasi, How can I get the all entries of work notes from bottom to top. currently I am using 'getJournalEntry(-1)' and it is fteching from top to bottom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 05:55 AM
I suggest you to play with the code below in a background script to get what you want.
In the example below the na array has the most recent work_note on position zero and so on.
If you want to grab/display them in the opposite order just invert the for loop.
//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = current.work_notes.getJournalEntry(-1);
//stores each entry into an array of strings
var na = notes.split("\n\n");
for (var i = 0; i < na.length; i++)
gs.info(na[i]);
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 06:17 AM
Hi,
Splitting on \n\n can cause some issues when the comments has 2 or more carriage returns, so, if you know that the work_notes start with a date in format YYYY-MM-DD HH:MM:SS it can be improved if \n\n are only matched when followed by a date and not including the date in the match with a lookahead assertion
//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = current.work_notes.getJournalEntry(-1);
//stores each entry into an array of strings
var na = notes.split(/\n\n(?=[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - )/);
for (var i = 0; i < na.length; i++)
gs.info(na[i]);
Cheers
J.Moral