unable to fetch variables in email script

Priyansh_98
Tera Guru

Hi,

I am writing an email script to print variables in my custom table email notification. but somehow it is not printing the variables in my notification. this script I am using in the RITM table, is working fine but in my custom table is not working.

this is my script.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    template.print('Short Description: ' + current.sysapproval.short_description + '<br><br>');
    template.print('PCASE Requested By Name: ' + current.sysapproval.opened_by.name + '<br>');
    template.print('PCASE Requested By ID: ' + current.sysapproval.opened_by.user_name + '<br>');
    template.print('PCASE Requested By Title: ' + current.sysapproval.opened_by.title + '<br>');
    template.print('PCASE Requested By Department: ' + current.sysapproval.opened_by.department.name + '<br>');
    template.print('PCASE Requested By Phone: ' + current.sysapproval.opened_by.phone + '<br>');
 

    var item = new GlideRecord("u_gbs_request_item");
    item.addQuery("sys_id", current.sysapproval);
    item.query();

    while (item.next()) {

     

        template.print('<div><div><hr /></div></div>');

        template.print("Summary of PCASE items:<br>");

        template.print('Options: item sys_ id : ' + item.sys_id + '<br>');


        var keys = new Array();
        var set = new GlideappVariablePoolQuestionSet();
        set.setRequestID(item.sys_id);
        set.load();
        var vs = set.getFlatQuestions();
        for (var i = 0; i < vs.size(); i++) {
            if (vs.get(i).getLabel() != '') {
                if (vs.get(i).getLabel() == 'Requested for') {
                    // Do nothing
                } else {
                    template.space(4);
                    template.print(vs.get(i).getLabel() + ": " + vs.get(i).getDisplayValue() + '<br>');
                }
            }
        }
        template.print('<br>Comments: ' + current.sysapproval.description);
    }
})(current, template, email, email_action, event);

 

please help me on this..

2 REPLIES 2

Koen Spiessens
Tera Contributor

What do you want to achieve exactly?

In my opinion triggering an event through business rule is far easier to launch notifications.
You can add specific conditions as to when the event has to be triggered.
You can send parameters through the event and use them in your notification.

hi @Koen Spiessens ,

 

but how will i fetch the variable values in this notification.. Actually, we have 100+ record producers which i targeting to this custom table only. and every record producer contains the average. 25+ variables also.. those variables i have to print in the email notification along with there values.