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

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

Hello @Ankur Bawiskar ,

 

  • Can we just show only variables that are visible on the RITM form including "Rich text" fields?
  • Can we hide fields on emails that are hidden based on conditions on RITM or on catalog items? 

 

 

Hi Ankur,

It is working fine. I have one small doubt.

We are populating the cmdb ci name to the catalog form by creating the reference field in the catalog form. Here I want to populate the status of the cmdb in the notification. 

Is it possible to achieve.

Hi Arun,

I believe your original question for showing variables in email is answered.

Can you please mark my response as correct and helpful so that this thread is closed and benefits others.

Regards
Ankur

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

Hi,

yes you can show by checking if the variable is referring to cmdb_ci and then dot walk and get status

Regards
Ankur

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