Fetch last added additional comments/work notes into email notification

Harish74
Tera Expert

Hi there,

I need to fetch recent additional comments/work notes into email notification. i have used current.comments.getJournalEntry(1) & current.work_notes.getJournalEntry(1) to achieve this. But I'm getting the time frame as well with the additional comments. Can I able to fetch only the comment/work notes ??

Eg: Work notes: This is a test work notes (I required)

Work notes: 2021-02-15 01:22:40 AM PST - User Name (Work notes) This is a test work notes (I don't required)

 

1 ACCEPTED SOLUTION

Hi,

try this

var rec = new GlideRecord('sys_journal_field');
rec.orderByDesc('sys_created_on');
rec.addQuery('name', current.getTableName());
rec.addQuery('element', 'work_notes');
rec.addQuery('element_id', current.sys_id);
rec.setLimit(1);
rec.query();
if(rec.next()){

template.print(rec.value);

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Hi,

try this

var rec = new GlideRecord('sys_journal_field');
rec.orderByDesc('sys_created_on');
rec.addQuery('name', current.getTableName());
rec.addQuery('element', 'work_notes');
rec.addQuery('element_id', current.sys_id);
rec.setLimit(1);
rec.query();
if(rec.next()){

template.print(rec.value);

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks, it worked

HI Harish74,
You can use this code in your script,
var workNotes= gr.work_notes.getJournalEntry(1);//'(Work notes)';
        gs.info('work notes:' +workNotes);
        var email_Delete = workNotes.indexOf('(Work notes)');
        var email_Comment = workNotes.slice(email_Delete + 12);
        agileWorkNotesArray.push(email_Comment);
 

Hi Harish,

 

If the work notes are not present on the record it will show Undefined. But for this you can check if lastwork is present in the record or not. Like Below code: 

 

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

  var worknoteContent = worknote.split("(Work notes)\n");

  var lastWorknote = worknoteContent[1];

if(lastWorknote)

{

template.print(lastWorknote );

}

Kajal Goti
Mega Guru

Hi,

 

You will get help from below thread

 

https://community.servicenow.com/community?id=community_question&sys_id=b07da0eddbef37442be0a851ca96...

 

 

Please mark as correct/helpful, If you find any help