- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 04:35 AM
Can I use input parameter in an email script?
I have this code on my notification's body
HTTP Status: ${u_notes}
${mail_script:ErrorReportNotificationScript}
<mail_script>errorReport(${u_notes});</mail_script>
And this on my Email Script
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) {
function errorReport(status){
if (status >= 400 && status < 499) {
template.print("<p>Client Error!</p>");
} else if (status >= 500 && status< 599) {
template.print("<p>Server Error!</p>");
} else {
template.print("<p>Error!</p>");
}
}
})(current, template, email, email_action, event);
I know that the code is not working but i put the code here just for an simple representation
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 05:12 AM
@joao_graca Unfortunately, you can't pass any parameters directly in email script from a notification body. However, you can still pass parameters through event parameters (Event param 1 or param 2). You can set these param values while triggering the event.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 05:34 AM
Hello joao_graca,
can you try this...!!
In the mail script you can get value of "u_notes" by using current object. then you can call errorReport function
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) {
//Get the value of notes
var status = current.u_notes;
//call the function
errorReport(status);
function errorReport(status){
if (status >= 400 && status < 499) {
template.print("<p>Client Error!</p>");
} else if (status >= 500 && status< 599) {
template.print("<p>Server Error!</p>");
} else {
template.print("<p>Error!</p>");
}
}
})(current, template, email, email_action, event);
Notification body :
HTTP Status: ${u_notes} ${mail_script:ErrorReportNotificationScript}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 05:12 AM
@joao_graca Unfortunately, you can't pass any parameters directly in email script from a notification body. However, you can still pass parameters through event parameters (Event param 1 or param 2). You can set these param values while triggering the event.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 05:28 AM
Hi @joao_graca
While you cannot directly pass parameters to an email script from a notification body, you can use event parameters to achieve a similar outcome.
Event parameters allow you to pass additional data when triggering an event.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) {
// Retrieve event parameters
var parm1 = event.parm1;
// Check if parm1 has a value
if (parm1) {
// Now you can use 'parm1' in your email script logic
if (parm1.indexOf("400") !== -1 || parm1.indexOf("499") !== -1) {
template.print("<p>Client Error!</p>");
} else if (parm1.indexOf("500") !== -1 || parm1.indexOf("599") !== -1) {
template.print("<p>Server Error!</p>");
} else {
template.print("<p>Error!</p>");
}
} else {
template.print("<p>No HTTP Status found!</p>");
}
})(current, template, email, email_action, event);
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 05:34 AM
Hello joao_graca,
can you try this...!!
In the mail script you can get value of "u_notes" by using current object. then you can call errorReport function
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) {
//Get the value of notes
var status = current.u_notes;
//call the function
errorReport(status);
function errorReport(status){
if (status >= 400 && status < 499) {
template.print("<p>Client Error!</p>");
} else if (status >= 500 && status< 599) {
template.print("<p>Server Error!</p>");
} else {
template.print("<p>Error!</p>");
}
}
})(current, template, email, email_action, event);
Notification body :
HTTP Status: ${u_notes} ${mail_script:ErrorReportNotificationScript}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates