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

Allen Andreas
Administrator
Administrator

Hi,

You can access those variables in the notification by using format like:

${variables.VARIABLE_NAME}

So if those are static variables, always there, you could write in notification:

Requested for: ${variables.requested_for}

Where "requested_for" is the name for the Requested for variable. 🙂

There are other ways too through using mail script, etc. but see if that works for you?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Is this for a Notification which always contains the same variables? Or might the variables differ/be dynamic/etc?

If it contains the same variables:
See the answer from Allen.

If the variables differ upon situation/dynamic etc:
You could set up a mail script. Mail script which retrieves all available variables and generates a summary or similar. For example see this article which I wrote a while ago, to create a summary of variables. This is just a way to achieve it, there are multiple ways. To you could use something similar within an email script.
Generate Catalog Item Variables summary

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

The variables in the Variable editor changes for each case created and we need to show the variables present on the Record in email notification. 

Please let me know if this will work for Record producer variables and in Scoped application .

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