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

Rajababu
Giga Guru

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

4 REPLIES 4

Chuck Tomasi
Tera Patron

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


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

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.


javiermoral
Giga Contributor

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