Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Unable to fetch email template

Samyak613
Tera Contributor
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? 

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