I am calling a mail script from notifications

kiran kumar m1
Tera Contributor

I am calling a mail script from notifications 

here is my code 

var gr = new GlideRecord('incident');
            gr.query();
            while (gr.next()) {
                var sr = new GlideRecord('sys_journal_field');
                sr.addQuery('element_id', gr.sys_id);
                sr.orderByDesc('sys_created_on');
                sr.query();
                if (sr.next()) {
                    var latestComment =gr.comments.getJournalEntry(1);
 }
return latestComments
 
but when I am calling this in my notification I cant see the preview of the comments , can anyone guide me where am i going wrong or is my code wrong 
8 REPLIES 8

DrewW
Mega Sage
Mega Sage

If memory serves you can just add ${comments} to the notification body and it will automatically include the last three.

 

But for your script you need to use template.print() and not a return value.

So replace 
var latestComment =gr.comments.getJournalEntry(1);

with

template.print(gr.comments.getJournalEntry(1));

 

swathisarang98
Giga Sage
Giga Sage

Hi @kiran kumar m1 ,

 

If you want your mail_script to show the comments and your notification is on incident table only then you can use the below single line code

 

 

 

template.print('<p><font size="3" color="#808080" face="helvetica">' + gs.getMessage('${comments}') + '</font></p>');

 

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

hii @swathisarang98  if it is a custom table then ?

Hii @swathisarang98 I have tried your code but its giving me output in this way . I am getting random numbers under the comments

kirankumarm1_0-1713898902032.png