How to include Request Item summary including variables in Request submitted notification

jituksingh
Kilo Guru

Hi All,

I want to include Request Item summary in the Request submitted notification to user. Currently it include only Req data like below. Now we need include variable information in the same email. Please suggest how we can do that?

find_real_file.png

I am using email notification

Your request has been received

Click here to view request: ${URI_REF}
Request Category: ${mail_script:print_category}
Request Subcategory: ${mail_script:print_subcategory}
Requested For: ${requested_for}
Opened: ${opened_at}
${mail_script:print_cat_item_request_submitted}

 

 

 

Thanks and Regards,

Jitendra Singh

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jituksingh 

You need to use email script in your email body and include it in email

Mail script: print_cat_item_request_submitted

Script

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

	// Add your code here

	template.print('Variable Summary: <br/>');
	
	var ritm = new GlideRecord('sc_req_item');
	ritm.get('request', current.sys_id);
	
	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();
		if(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

View solution in original post

11 REPLIES 11

@jituksingh 

Are you using same email script for REQ and SC Task notification?

If yes then please create separate ones

For REQ

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

	// Add your code here

	template.print('Variable Summary: <br/>');
	
	var ritm = new GlideRecord('sc_req_item');
	ritm.get('request', current.sys_id);
	
	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();
		if(label != ''){
			template.space(4);
			template.print('  ' + label + " = " + value + "<br/>");
		}
	} 

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

For SC Task

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

	// Add your code here

	template.print('Variable Summary: <br/>');
	
	var ritm = new GlideRecord('sc_req_item');
	ritm.get('request', current.request_item);
	
	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();
		if(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

I tried adding this script but for me it is not working. It is not showing any variables in the notification which are there in the form. The only thing it is showing is Variables Summary.