Adding RITM Variables in Approval Mail Notification

Arun87
Giga Contributor

Hi,

I have one catalog item named as xyz which contains workflow name as yz. When user raised a request it will be go for the user's manager approval. In the approval email few fields are need to visible. 

Approval email is sending for sysapprover table. Could anyone please help on this.

1 ACCEPTED SOLUTION

Hi,

I didn't get.

Since user has filled 10 variables those 10 will come in email.

Why to display only 5 variables? are you saying you want to keep specific variables only and exclude some 5?

if yes then try this

ensure you give valid variable names in the if condition

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

          (function runMailScript(current, template, email, email_action, event) {

    // Add your code here

    template.print('Summary of requested item: <br/>');

    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('sys_id', current.sysapproval);
    ritm.query();
    if(ritm.next()){
        var variables = ritm.variables.getElements();
        for (var i=0;i<variables.length;i++) {
            var question = variables[i].getQuestion();
            var label = question.getLabel();
            var value = question.getDisplayValue();
            var name = question.getName();

            if(name != 'variable1' && name != 'variable2' && name != 'variable3' && name != 'variable4' && name != 'variable5'){
            if(label != '' && value != ''){
                template.space(4);
                template.print('  ' + label + " = " + value + "<br/>");
            }
            }
        }
    }

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

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

Regards
Ankur

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

View solution in original post

14 REPLIES 14

Jaspal Singh
Mega Patron
Mega Patron

Hi Arun,

 

You can have a mail script named: getrequiredvariables with code as below.

(function runMailScript(current, template, email, email_action, event) {
	
template.print("<b>Summary of Requested items:\n</b>");
var getvariables=new GlideRecord('sc_req_item');
getvariables.addQuery('sys_id',current.sysapproval);
getvariables.query();
while(getvariables.next())
{
 template.print('Var 1 '+getvariables.variable_name1);//replace variable name
 template.print('Var 2 '+getvariables.variable_name2); //replace variable name
}
}

 

Call mail script in notification body of Approval table notification in format

${mail_script:getrequiredvariables}

Hi,

It is not working for the reference field.

Hi Arun,

Can you please check my comment and script shared

Regards
Ankur

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

Hi Arun,

 

It is not working as the syntax has an issue. Line below was missed as it should be last line.

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

In other words, you need to use below.

(function runMailScript(current, template, email, email_action, event) {
	
template.print("<b>Summary of Requested items:\n</b>");
var getvariables=new GlideRecord('sc_req_item');
getvariables.addQuery('sys_id',current.sysapproval);
getvariables.query();
while(getvariables.next())
{
 template.print('Var 1 '+getvariables.variable_name1);//replace variable name
 template.print('Var 2 '+getvariables.variable_name2); //replace variable name
}
})(current, template, email, email_action, event);