
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 02:01 PM
Hello Friends,
Greetings!
I actually need some help in writing some mail script.
I wanted to populate the variable details (Which are catalog item variable) in a mail script and wanted to call the mail script by an email template.
An email is triggering to the approver and we want to add some variables in that email template so that approver can easily approve/ reject the mail by seeing the details present on it. (Those variables are from that catalog item).
I have tried many ways to fetch the variables but failed. Please some mail script by which I can able to do this.
Thanks
Rajesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 04:16 PM
Hello @Community Alums
You can try something like below in the mail script:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
if (!gs.nil(current.getTableName()) && !gs.nil(current.document_id) && !gs.nil(current.sysapproval)) {
if (current.getTableName() == "sysapproval_approver" && current.source_table == "sc_req_item" && current.state == "requested") {
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval.toString());
gr.query();
if (gr.next()) {
template.print("Variables Information:<br>");
template.print("Requested for: " + gr.variables.requested_for.name.toString());
}
}
}
})(current, template, email, email_action, event);
You can call this in the email template like below format:
<div>${mail_script:your_mail_script_name}</div>
NOTE: Make sure your notification is on approval table and approval should be in requested state.
You can add as many as variables you wanted to display in the notification.
(=tested)
Let me know if you still stuck anywhere
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 04:16 PM
Hello @Community Alums
You can try something like below in the mail script:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
if (!gs.nil(current.getTableName()) && !gs.nil(current.document_id) && !gs.nil(current.sysapproval)) {
if (current.getTableName() == "sysapproval_approver" && current.source_table == "sc_req_item" && current.state == "requested") {
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval.toString());
gr.query();
if (gr.next()) {
template.print("Variables Information:<br>");
template.print("Requested for: " + gr.variables.requested_for.name.toString());
}
}
}
})(current, template, email, email_action, event);
You can call this in the email template like below format:
<div>${mail_script:your_mail_script_name}</div>
NOTE: Make sure your notification is on approval table and approval should be in requested state.
You can add as many as variables you wanted to display in the notification.
(=tested)
Let me know if you still stuck anywhere
Murthy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 10:08 AM
Thanks Murthy, This works.
Thanks for your help.