2017年8月3日 星期四

[ServiceNow] Email Notification using template

Create email scripts (optional)

System notifications > Email > Notification Email Scripts

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

template.print( gs.getMessage('sakatsuku is interesting') );

// add req item vars to email content
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sys_id);
item.query();
while(item.next())
{
var catalogItem = item.number + ': ' + item.cat_item.getDisplayValue();
var misc = item.variable_pool.alt_poc;
template.print(catalogItem + "<br/> Field: " + misc);
}

})(current, template, email, email_action, event);

Build a template

System policy > Email > Templates

Name: xxx
Subject: xxxx
Table: choose a table
Message HTML:
${mail_script: your_email_script}

Create a notification


System notifications > Email > Notifications

In tab "What It Will Contain", choose a email template.

沒有留言:

張貼留言