- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2015 07:27 PM
Hey Again all you Genius's. I need your help again.
This is kind of a "idea" rather than it being functional (i think).
So here's the deal.
I love ${mail_script:scriptname} it's awesome. Very functional, works like a charm.
We have a request item that we have an approval email for. Then there is a UI action that was create to fire an Event. We created a 2nd email notification to accept this event to fire the "Resend email"
here's the deal.
The approval email we have a ${mailscript} at the very top which contains our approval/reject links. and Information about the request.
Then we have the BODY of the email. Contains the variables of the request.
Then we have 2 ${mailscript}'s at the bottom with some "for the administrator" which tells us the ticket number, what email notification send this email, and so forth.
Here is where the question comes in. We cant use an HTML template for all the notifications because we add different ${mailscripts}
What i'm wanting to know is:
Can we Create a template, that is dynamic like the mail scripts
So in my email notification, i dont have a template "attached" and used.
BUT. i used something like ${template:templatename} Because the body of my email wont change.
Is there a way to do something like so.
${mail_script:Approval-Reminder}
${mail_script:Approval-Links}
${template:templatename}
${mail_script:Approval-Additional}
${mail_script:Approval-Administrator}
Where the ${template} will actually pull the HTML data out of the template.
This way i would only have to update it 1 time and it would update in all 3 of my notifications.
I do not want to use the text box. i want to use HTML. i dont want to have to use the <mail_script> template.print() for every single line, Hence using the HTML (WYSIWYG)
Does that make any sense at all?
it would be great for the templates if you attach it as is to the email and it's used with no modifications. or if you could "call" the template data into the actual email notification like the mailscripts.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2015 08:03 PM
So i found my answer. Dot Walk.
Create an email script, say called "template"
Script will be
template.print(email_action.template.message_html);
That will take the reference field of the "template" from the email notification and then pull the HTML field from the template.
Then in the email notification you can do a ${mail_script:template} and that is all that is needed.
So now my email Notification html box looks like so:
It will translate into this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 10:10 AM
Hello Daniel,
Were you able to make any headway with your suggested idea of "add any mail template dynamically to a notification based on any given conditions"?
Thank you,
Kevin Eldridge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2017 07:19 PM
Hi Kevin,
you can do this by, e.g...
///////////////////////////////////////
1) setting up 3 templates...
- 'email_template_header' & 'email_template_footer' containing only their respective html
- 'email_template_body' - as per 2) below...
///////////////////////////////////////
2) 'email_template_body'...
${mail_script:email_script_header}
<<< BODY HTML >>>
<<< BODY HTML >>>
<<< BODY HTML >>>
${mail_script:email_script_footer}
///////////////////////////////////////
3) and, e.g., the 'email_script_header' would be something like...
var gr = new GlideRecord('sysevent_email_template');
gr.addQuery('name', 'email_template_header');
gr.query();
if (gr.next()) {
template.print(gr.message_html);
}
///////////////////////////////////////
4) the notification would then use the 'email_template_body' in the 'Email Template' field... or... you could skip the 'email_template_body' altogether and put the html for that (ref 2 above) directly inside the notification
///////////////////////////////////////
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2017 09:10 AM
Would you mind sharing how you're pulling thoserequest variables like that for the approval emails? It would really be beneficial to our customers as well. We've tried to pretty up these emails but we're not that great at it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2017 09:50 AM
From the Approval email you have to dot walk.
so if you're running the email notification from the approval table,
you need to have the variable ${current.sysapproval.variables.(variable)}
so on the form, if your variable name is first_name then you're going to have ${current.sysapproval.variables.first_name}
that is just going to pull in the data from the field. it will not pull in the "Question"
if you look at the very first picture at the top, you'll see this.
Additionally if you wanted to run a mail script, here is an example of the script that we run for the approval process
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
// ${mail_script:Loaner Computer} Mail script name for use in the Email Notifications
var item = new GlideRecord('sc_req_item');
item.addQuery('sys_id', current.sysapproval);
item.query();
if (item.next()) {
template.print("Acknowledgement: <font color = '#FF0000'><b> In submitting this loaner request, I understand that my department is responsible for this equipment and will return requested equipment at the end of this loan time in the condition that it was received. If the equipment is lost, stolen or damaged, I agree that my department will replace the equipment at the current cost of replacement.</font></b><br />");
template.print("Acknowledgement: <font color = '#000080'><b>" + item.variables.acknowledgement.getDisplayValue() + "</font></b><br />");
template.print("<br /><br /><b>USER INFORMATION</b><br />");
if(!item.variables.requestedfor_name.nil()){
template.print("Requested for Name: <font color = '#000080'><b>" + item.variables.requestedfor_name.getDisplayValue() + "</font></b><br />");
}
if(!item.variables.requestedfor_phone.nil()){
template.print("Requested for Phone: <font color = '#000080'><b>" + item.variables.requestedfor_phone + "</font></b><br />");
}
if(!item.variables.requestedfor_alternate_phone.nil()){
template.print("Alternate Phone: <font color = '#000080'><b>" + item.variables.requestedfor_alternate_phone + "</font></b><br />");
}
template.print("<br /><b>USER LOCATION</b><br />");
if(!item.variables.requestedfor_location_type.nil()){
template.print("Location Type: <font color = '#000080'><b>" + item.variables.requestedfor_location_type.getDisplayValue() + "</font></b>");
}
if(!item.variables.requestedfor_campus.nil()){
template.print("<br />Campus: <font color = '#000080'><b>" + item.variables.requestedfor_campus.getDisplayValue() + "</font></b>");
}
if(!item.variables.requestedfor_floor.nil()){
template.print("<br />Floor: <font color = '#000080'><b>" + item.variables.requestedfor_floor.getDisplayValue() + "</font></b>");
}
if(!item.variables.requestedfor_suite.nil()){
template.print("<br />Wing/Suite/Dept: <font color = '#000080'><b>" + item.variables.requestedfor_suite.getDisplayValue() + "</font></b>");
}
if(!item.variables.requestedfor_practice.nil()){
template.print("<br />Practice Name: <font color = '#000080'><b>" + item.variables.requestedfor_practice.getDisplayValue() + "</font></b>");
if(item.variables.requestedfor_practice.u_non_ghs == true){
template.print("<font color = '#ff0000'><b> - THIS IS A 3RD PARTY/NON OWNED LOCATION</font></b>");
}
}
if(!item.variables.requestedfor_street.nil()){
template.print("<br />Street Address: <font color = '#000080'><b>" + item.variables.requestedfor_street.getDisplayValue() + "</font></b>");
}
template.print("<br />");
if(!item.variables.requestedfor_other.nil()){
template.print("Additional Location Info: <font color = '#000080'><b>" + item.variables.requestedfor_other + "</font></b><br />");
}
if(!item.variables.loaner_computer.nil()){
template.print("Loaner Computer Hostname <font color = '#000080'><b>" + item.variables.loaner_computer.getDisplayValue() + "</font></b>\n");
}
if(!item.variables.requestedfor_cost_center.nil() || !item.variables.requestedfor_cost_center_number.nil()){
template.print("\n\n<b>COST CENTER SECTION</b>\n");
if(!item.variables.requestedfor_cost_center.nil()){
template.print("Requested For Users: Cost Center? <font color = '#000080'><b>" + item.variables.requestedfor_cost_center.getDisplayValue() + "</font></b>\n");
}
if(!item.variables.requestedfor_cost_center_number.nil()){
template.print("Cost Center Number <font color = '#000080'><b>" + item.variables.requestedfor_cost_center_number+"</font></b>\n");
}
}
template.print("\n\n<b>REQUEST DETAILS SECTION</b>\n");
if(!item.variables.loaner_start.nil()){
template.print("Loan Start Date (mm-dd-yyyy): <font color = '#000080'><b>" + item.variables.loaner_start.getDisplayValue()+"</font></b>\n");
}
if(!item.variables.loaner_end.nil()){
template.print("Loan End Date (mm-dd-yyyy): <font color = '#000080'><b>" + item.variables.loaner_end.getDisplayValue()+"</font></b>\n");
}
if(!item.variables.number_requested.nil()){
template.print("Number of Computers Requested? <font color = '#000080'><b>" + item.variables.number_requested.getDisplayValue() + "</font></b>\n");
}
if(!item.variables.loaner_short_description.nil()){
template.print("Short Description (please summarize your request) <font color = '#000080'><b>" + item.variables.loaner_short_description+"</font></b>\n");
}
if(!item.variables.loaner_dept.nil()){
template.print("Which department is the computer going to be used? <font color = '#000080'><b>" + item.variables.loaner_dept+"</font></b>\n");
}
if(!item.variables.loaner_dock.nil()){
template.print("Do you need a docking station <font color = '#000080'><b>" + item.variables.loaner_dock.getDisplayValue()+"</font></b>\n");
}
if(!item.variables.loaner_alt_contact.nil()){
template.print("Alternate Contact: <font color = '#000080'><b>" + item.variables.loaner_alt_contact.getDisplayValue()+"</font></b>\n");
}
if(!item.variables.loaner_alt_contact_phone.nil()){
template.print("Alternate Contact Phone: <font color = '#000080'><b>" + item.variables.loaner_alt_contact_phone+"</font></b>\n");
}
if(!item.variables.loaner_purpose.nil()){
template.print("Loaner Purpose: <font color = '#000080'><b>" + item.variables.loaner_purpose+"</font></b>\n");
}
if(!item.variables.loaner_setup.nil()){
template.print("\nAdditional Software Needed / Other Requirements: <font color = '#000080'><b>\n" + item.variables.loaner_setup+"</font></b>\n");
}
if(!item.variables.additional_time.nil()){
template.print("Additional Time: Pickup Date <font color = '#000080'><b>" + item.variables.additional_time.getDisplayValue()+"</font></b>\n");
}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2020 04:09 AM
Hello,
This is a very useful way to use both template and Message HTML field at a time. But is my case, I have used a mail script in the template as well. And when I use template this way, it doesn't return the expected value, and returns only plain text. It would be helpful if you could suggests some solution to this.
Thanks,
Priyanka