The Zurich release has arrived! Interested in new features and functionalities? Click here for more

QUESTION RELATED TO MAIL SCRIPT

adityahubli
Tera Contributor
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
            var grp=current.assignment_group;
            var gr=new GlideRecord('sys_user_grmember');
            gr.addQuery('group',grp);
            gr.query();
            while(gr.next())
            {
                email.addAddress('cc',gr.user.email,gr.user.first_name);
            }
            email.setSubject('Incident Assignment!!!')
            email.setBody('New Incident has been assigne to your '+gr.getDisplayValue('group'));
            email.setReplyTo(gr.user.manager.email);

 

template.print('Hello This isbfjbjsdgjm');   
          // Add your code here

 

})(current, template, email, email_action, event);
 
 
first time when I run this script without template.print() method notification didn't got  send but when I
added template.print() in code then notification get send , why without template.print notification get send ?
2 ACCEPTED SOLUTIONS

@adityahubli 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

M Iftikhar
Mega Sage

Hi @adityahubli ,

The reason your email didn’t send without template.print() is that the notification engine requires some body content to process.

  • If the notification record itself does not have a body defined, the mail script must produce output (via template.print()) to generate the body.

  • If you define a body in the notification (e.g., static text or variables), then template.print() is not required, and your script can just handle recipients, subject, etc.


I found this in the ServiceNow TemplatePrinter API which provides methods to handle printing from a mail script to the email message u will find this doc helpful:
https://developer.servicenow.com/dev.do#!/reference/api/zurich/server/no-namespace/c_TemplatePrinter...


Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

View solution in original post

10 REPLIES 10

M Iftikhar
Mega Sage

Hi @adityahubli ,

The reason your email didn’t send without template.print() is that the notification engine requires some body content to process.

  • If the notification record itself does not have a body defined, the mail script must produce output (via template.print()) to generate the body.

  • If you define a body in the notification (e.g., static text or variables), then template.print() is not required, and your script can just handle recipients, subject, etc.


I found this in the ServiceNow TemplatePrinter API which provides methods to handle printing from a mail script to the email message u will find this doc helpful:
https://developer.servicenow.com/dev.do#!/reference/api/zurich/server/no-namespace/c_TemplatePrinter...


Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.