Notification Email script with parameters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2017 07:49 AM
Hello ,
Can we use parameters when calling email script to do something like this : ${mail_script:show_informations("first info","second info")} ?
Thank you !
- 13,806 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2017 07:55 AM
The script has access to the current object. Would this be sufficient for what you are looking to do?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2017 07:55 AM
Hi Abdel,
You can wrap you code inside a function (in the email script).
Then call it with the parameters you need.
Example of email script:
- function generateTemplate(name, table){
- template.print("<p></p>" + name + ":<br />");
- var gr = new GlideRecord(table);
- gr.addQuery("request", current.sys_id);
- gr.query();
- while(gr.next()) {
- template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + ", Stage: " + gr.stage.getDisplayValue() + "<br />");
- }
- }
And then on your notification:
- ${mail_script:req_items}
- <mail_script>
- generateTemplate("Requested items", "sc_req_item");
- </mail_script>
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2017 09:00 AM
Hi Sachin,
it could be a nice solution but i have to use the mail script inside the href attribute of a link : <a href="link1?${mail_script:printParams("value1","value2")}">go</a>
with many links we will have a lot of <mail_script>.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 10:32 AM
This approach didn't worked for me.
I'll just do all of my custom logic inside of my mail_script, like Chuck mentions below, any custom parameters that should be needed can be retrieved via the event object or the current object being displayed. However, having the power to pass parameters directly to the mail script would had been cool. 😞