Mail Script Parameters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2015 04:49 AM
Hello Gurus,
is there a way to pass an argument in to an email script when it is called from within an email template/notification ?
Including an email notification script as follows:
${mail_script:req_items}
Actual Script:
template.print("<p></p>Requested items:<br />");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while(gr.next()) {
template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + ", Stage: " + gr.stage.getDisplayValue() + "<br />");
}
Cheers
- Labels:
-
Analytics and Reports
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2015 04:45 AM
Hi Maros,
if the "current" record that the email template is working on is a record from the sc_req_item table that script should work.
If the current record instead is an event, you would be using the sys_id of the event record not the sys_id of the request.
You could use current.parm1 or current.parm2 if the event is the current record and save the sys_id you need in the parm1 or parm2 fields.
If neither of the above is valid in your case, can you give more details please?
Thanks and kind regards,
Alexandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2015 08:59 AM
Alexandra,
I am looking to reuse the same Mail Script on a number of templates, which can be linked to different tables such as Request and/or Approval, so Current would not always refer to the Request Table.. Also, a section title would usually say "Requested Items", but there maybe cases in which this would have to change, hence the need to have parameters for all these configurable options... does that make sense?
Cheers
Maros
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2015 06:54 PM
Hi Maros,
I've been looking to do the same sort of thing with mail scripts but have not found any documentation or other mention of being able to add parameters to mail scripts...
Saying that I have been using script includes to reduce some of the repetition, this still means using a different mailscript in each notification, but putting the reusable piece into a script include and passing the parameters to it.
If you do find a method for adding parameters directly to mail scripts please share as it would be of great benefit.
Cheers
Russ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2015 07:57 PM
Hello,
An alternative would be to 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>
This is definitely not a very clean solution but it can help to reuse the email scripts. I think that email scripts were designed to be used as traits not really as a method of abstraction.
Thank you.