getJournalEntry method - wanna just entry without user and timestamp

nikita_mironov
Kilo Guru
 
1 ACCEPTED SOLUTION

nikita_mironov
Kilo Guru

OK. Answrting myself:
var work_notes = current.work_notes.getJournalEntry(1)
var regex= new RegExp('\n'); // searching for the first line break
var work_notes2=work_notes;
var i = work_notes.search(regex);
if (i>0)
{
// taking everything after the first line break, he-he.
work_notes2 = work_notes.substring(i+1, work_notes.length);
}
gs.log('pure work notes:'+work_notes2);


View solution in original post

8 REPLIES 8

TylerTeter
Kilo Guru

To be clear, there is an alternate way of approaching this. Just look up the journal entry yourself and output the value.

 

Example code (borrowed from https://hi.service-now.com/kb_view.do?sysparm_article=KB0529930&sysparm_topic=Known+Error+Database

var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id',current.sys_id);
gr.addQuery('name','task');
gr.query();
while( gr.next() ) {
  gs.print( gr.element + ' = ' + gr.value );
}

dheeraj10
Kilo Contributor

MORE SIMPLIFIED SOLUTION:-

var work_notes = current.work_notes.getJournalEntry(1)

var i = work_notes.indexOf('\n'); 

if (i>0)
{
// taking everything after the first line break, he-he.
work_notes2 = work_notes.substring(i+1, work_notes.length);
}
gs.log('pure work notes:'+work_notes2);

 

 

Sigval Bergesen
Tera Contributor

var list = current.comments.getJournalEntry(1).split('\n'); // split into list of sentences
list[0] = '';  // clear the first sentence
var text = list.join('\n'); // combine all sentences again into one single string, now without no header

if you are using this for an outbound email like a notification or something, you might want to combine the text using join('</br>'); instead for html new line. works perfectly fine