getJournalEntry() to return the latest comment added - script logic not working

chatsaurav19
Tera Contributor

Hi All,

 

Through a script include, I am trying to return the latest journal entry but it is not working. Can someone please help to correct the script?

 

var arr = [];

var gr1 = new GlideRecord('table');
gr1.addQuery('sy_id', this.getParameter('sysparm_roleID'));
gr1.query();
if (gr1.next()) {

arr.push(gr1.getDisplayValue('role_title'));
arr.push(gr1.level.getDisplayValue());

arr.push(gr1.comment.getJournalEntry(-1)); //Comment is the field name which is journal type; Not Working

}

return JSON.stringify(arr);

 

chatsaurav19_0-1691081384386.png

 

 

Thanks and Regards,

Saurabh Chatterjee

 

7 REPLIES 7

sushantmalsure
Mega Sage
Mega Sage

I have corrected the code a bit try it.

 

var arr = [];

var gr1 = new GlideRecord('table'); // have correct table name instead of 'table' here
gr1.addQuery('sys_id', this.getParameter('sysparm_roleID')); //sys_id is correct field name
gr1.query();
if (gr1.next()) {

arr.push(gr1.getDisplayValue('role_title'));
arr.push(gr1.level.getDisplayValue());

arr.push(gr1.comments.getJournalEntry(-1)); //correct field name is comments not comment
}

return JSON.stringify(arr);

have added comment above where your input needed and places where i corrected

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi @sushantmalsure ,

 

Thank you for your reply!

 

It worked by adding 'comment' only. But the challenge is, it is returning all the comments but I only need the last comment.

 

Thanks and Regards,

Saurabh Chatterjee

Hello you need to use getJournalEntry(1) instead of -1

getJournalEntry(1) gets the latest entry.

getJournalEntry(-1) gets all entries.

Regards
Harish

then use '

gr1.comments.getJournalEntry(1))

'

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure