Display variable and Multiple row variable sets data into approver email.

Insider
Giga Guru

Hello,

I am trying to display variable and multiple row variable set data in an approval email notification.

in a line by line manager. as shown in the picture.

 

Process: A case gets created with variables and multiple row variable sets, then approver gets triggered and then this email gets triggered to approver.
i am currently using this script in email script to print the variable data but now i need for both variables and multiple row variable sets.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
 
    template.print('<table border="1">');
    var item = new GlideRecord('x_gskgs_gsf_case_1_finance_procurement_case');
    item.get('sys_id', current.sysapproval);
    for (var key in item.variables) {
        template.print("<tr>");
        if (item.variables[key]) {
            gs.info("Hello  " + getQuestionLabel(key));
 
            if (getQuestionLabel(key) != 'Routing Type' && getQuestionLabel(key) != 'undefined' && getQuestionLabel(key) != ' ' && item.variables[key].getDisplayValue() != ' ' && item.variables[key].getDisplayValue() != 'false' && getQuestionLabel(key) != 'false') {
                template.print("<td>" + getQuestionLabel(key) + "</td>\r\n");
                template.print("<td>" + item.variables[key].getDisplayValue() + "</td>\r\n");
                template.print("</tr>");
            }
        }
 
    }
    template.print("</table>");
 
    function getQuestionLabel(question) {
        var vara = new GlideRecord('item_option_new');
        vara.addQuery('name', question);
        vara.query();
        if (vara.next()) {
gs.info('variable '+vara.question_text+"  "+question);
            var question_label = vara.question_text;
            return question_label;
 
        }
    }
})(current, template, email, email_action, event);
 
Please help!
6 REPLIES 6

@Insider 

for normal variables you already have the above logic; just add the script shared in the article

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello @Ankur Bawiskar 
I tried the following script to print the variable data, it is working fine.
But how to dynamically print the varible set data along with these? please help with the script

My script:

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

template.print("<table border = 0.5 style=width:100% bgcolor='white'>");
var item = new GlideRecord('finance_table');
item.get('sys_id', current.sysapproval);

for (var key in item.variables) {
if (key != 'gsf_routing_type_service_offering' && key != 'csm_requested_for' && key != 'routing_type') {
template.print("<tr>");
if (item.variables[key]) {
template.print("<td><strong>" + getQuestionLabel(key) + "</strong></td>\r\n");
template.print("<td>" + item.variables[key].getDisplayValue() + "</td>\r\n");
template.print("</tr>");
}

}

}
template.print("</table>");


function getQuestionLabel(question) {
// gs.info('Give me question value ' + question);
var vara = new GlideRecord('item_option_new');
//vara.addEncodedQuery('name!=internal_contact^ORname!= gsf_routing_type_service_offering^name='+question);
vara.addQuery('name', question);
vara.query();
if (vara.next()) {
gs.info('variable ' + vara.question_text + " " + question);
var question_label = vara.question_text;
return question_label;

}
}


})(current, template, email, email_action, event);