How to include variable editor variables in Email notification

Mrman
Tera Guru

Hi All,

I have configured the variable formatter and added a Section on HR case record to show the Record producer variables submitted by employee on to the HR case as shown below . 

Please help me with a requirement to include these variables under 'Case details submitted' section in the Email Notification sent to the employee when case is submitted .

I am not finding a way to call these variables in Notification , please guide.

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ramamr 

You need to use email script for this

Name: show_variables

Script:

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

	// Add your code here

	template.print('Variables: <br/>');
	
	var variables = current.variables.getElements(); 
	for (var i=0;i<variables.length;i++) { 
		var question = variables[i].getQuestion();
		var label = question.getLabel();
		var value = question.getDisplayValue();
		if(label != ''){
			template.space(4);
			template.print('  ' + label + " = " + value + "<br/>");
		}
	} 

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

Then include it in the email notification like this

${mail_script:show_variables}

Regards
Ankur

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

View solution in original post

19 REPLIES 19

Tom Thompson
Tera Expert

This works great, Is there a way to limit which are sent?

I have a Variable that is option one Html and option two Html and it's including the unselected option also.

Hi,

The above script will include all variables in email.

If you wish to exclude specific ones you need to enhance the script

like this

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

    // Add your code here

    template.print('Variables: <br/>');

    var variables = current.variables.getElements();
    for (var i=0;i<variables.length;i++) {
        var question = variables[i].getQuestion();
        var label = question.getLabel();
        var value = question.getDisplayValue();
        if(label != '' && label != 'YOUR VARIABLE LABEL'){
            template.space(4);
            template.print('  ' + label + " = " + value + "<br/>");
        }
    }

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

Regards
Ankur

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

Thanks for the Quick feedback, 

@Ankur Agarwal 

I have a requirement to make only few record producer variables as Editable and remaining as Read only . 

Please see below variables in variables editor , only the yellow highlighted ones should be Editable, others should be read only .

Please let me know how to achieve this.

find_real_file.png

Hi,

You can use Catalog UI Policy and Catalog UI Policy Actions

Applies on Target record - True

Then add your variables which you want to make readonly in UI policy actions

Regards
Ankur

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