shloke04
Kilo Patron

Hi All,

Recently in my Project there was a requirement to display Variable Information in Notifications for a Record Producer submitted in a Scoped Application. Similar Requirement in Global Scope we implemented by using the Glide object "getGlideObject()" in Email Script, but with Scoped Application "getGlideObject()" does not works as it is not supported. Please refer the links of Scoped Application Supported objects:

https://developer.servicenow.com/app.do#!/api_doc?v=london&id=no-namespace

Below is the Scenario we had and script which we came up with for getting this done in Scoped App:

1) Once the Record Producer is submitted, an Approval Record gets generated.

2) Notification to the Approver is sent to Approve/Reject the Request within which we also wanted to display to the Approver with the list of Information filled in by the user while submitting the form.

3) Notification is on the Approval Table and for Displaying the Variable Information, an Email Script is being called in the Notification in the same Custom Scope as listed below:

 

Script:

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
	
	// Add your code here
	
	
	template.print('<table border="1">');
	var tbl_obj = new GlideRecord('Table Name');
	tbl_obj.get('sys_id',current.sysapproval);
	for (var key in tbl_obj.variables) {
		template.print("<tr>");
		if(tbl_obj.variables[key]){
			template.print("<td>" + getQuestionLabel(key) + "</td>\r\n");
			template.print("<td>" + tbl_obj.variables[key].getDisplayValue() + "</td>\r\n");
			template.print("</tr>");
		}
		
	}
	template.print("</table>");
		
	function getQuestionLabel(question){
		var vara = new GlideRecord('item_option_new');
		vara.addQuery('name',question);
		vara.query();
		if(vara.next()){
				var question_label = vara.question_text;
				return question_label;
			
		}
	}
	
	
})(current, template, email, email_action, event);

 

 

I have seen couple of post in Community forum for the discussion on the same topic, just wanted to share the way I did. Hope this helps.

 

Regards,

Shloke

Comments
Jace Benson
Mega Sage

That is very very clean.  I like it!  Thanks for sharing

shloke04
Kilo Patron

Thanks @jacebenson for the feedback!!

 

Regards,

Shloke

Troy Jensen
Tera Contributor

Thank you for this post!  Very nice and very easy to use!  

BTW...What up @jacebenson ???   : )

Jace Benson
Mega Sage

Hey Troy, hope all is well across town.  Stay safe, stay distant.

Servicenow12
Tera Contributor

Hello ,

I just want few of the variables on my Approval Notification? How can i use this in that case ? Could you suggest plz

Version history
Last update:
‎01-04-2019 06:59 PM
Updated by: