Unable to fetch email template
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2024 10:03 PM
I am facing an issue with email template, I am able to open the email outlook draft but the email template content is not fetched and returns null. I have set it up as when a user clicks on a button it triggers a function which calls the correct email template based on a field's content which is Illegal Activations or Double Activations.
Can someone please help?
Can someone please help?
Widget Editor's Function for triggering script include :
c.sendEmail = function() {
var ga = new GlideAjax('GetEmailTemplate');
ga.addParam('sysparm_name', 'getEmailBody');
ga.addParam('sysparm_subject', c.subject);
ga.addParam('sysparm_greetingName', c.greetingName);
ga.getXMLAnswer(function(response) {
console.log('Server response:', response);
var templateContent = response;
var encodedTo = encodeURIComponent(c.to);
var encodedCc = encodeURIComponent(c.cc);
var encodedSubject = encodeURIComponent(c.subject);
var encodedBody = encodeURIComponent(templateContent);
var mailToLink = "mailto:" + encodedTo + "?cc=" + encodedCc + "&subject=" + encodedSubject + "&body=" + encodedBody;
window.location.href = mailToLink;
});
Script Include :
var GetEmailTemplate = Class.create();
GetEmailTemplate.prototype = {
initialize: function() {},
getEmailBody: function() {
var subject = this.getParameter('sysparm_subject');
var greetingName = this.getParameter('sysparm_greetingName');
var version = this.getParameter('sysparm_version') || 'none';
var templateName = (subject === "Illegal Activations") ?
"Illegal Activations Email Template" : "Double Activations Email Template";
var template = new GlideRecord('sysevent_email_template');
template.get('name', templateName);
var body = template.getValue('body');
body = body.replace('${greeting_name}', greetingName);
return body;
},
type: 'GetEmailTemplate'
};
0 REPLIES 0