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

After looking at your code a gain its because you asked it to add the comment for every incident in your incident table.

Assuming this notification is for an incident and you want the last comment and only the last comment then your script just needs to be

 

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

 

and nothing else, no loop no GlideRecord queries.

 

Hi @kiran kumar m1 ,

 

 

var latestComment;
        var gr = new GlideRecord('incident');
        gr.query();
        while (gr.next()) {
            gs.info('inside while');
            var sr = new GlideRecord('sys_journal_field');
            sr.addQuery('element_id', gr.sys_id);
            sr.orderByDesc('sys_created_on');
            sr.query();
            if (sr.next()) {
                latestComment = gr.comments.getJournalEntry(1);
                gs.info("line num" + latestComment);
                template.print(latestComment +'<br>');
                 }
            }

 

here the variable declared was scoped so moved it to top and used template.print try the above code and let me know if it works or not ?

 

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

Regards,

Swathi Sarang

@kiran kumar m1 Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query.

 

Thanks,

Swathi

Karunakaran
Mega Guru

Hi @kiran kumar m1 ,

 

What @DrewW  is saying is making sense.

 

Please describe your requirement clearly in detail one more time so that you will get the exact solution.

 

If it is only comments, you can use ${comments}.

 

Thanks,

 

Regards,

Karunakaran.