Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Using RITM Variable in Approval email notification

Joe Taylor
Giga Guru

I have a Catalog Item called "Employee Onboarding".

The first step in my workflow is a group approval.

I'd like to send out the approval notification request with the name of the  new employee in the subject line.

The variable on the requested item is:  "legal_name".

The notifications are being triggered from the "sys_approval" table, but variable is somewhere in the "requested_item" table I think.

Can this be done?

1 ACCEPTED SOLUTION

Heya Joe,

Yeah this is possible. Again this will need to be done in a mail script as you're hoping through related records to get the information.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here
	
	var RITM = current.document_id.getRefRecord();
	
	var workflowGR = new GlideRecord('wf_context');
	workflowGR.addQuery('id', RITM.sys_id);
	workflowGR.setLimit(1);
	workflowGR.query();
	
	if(workflowGR.next()){
		var activityGR = new GlideRecord('wf_executing');
		activityGR.addQuery('context',workflowGR.sys_id);
		activityGR.query();
		if(activityGR.next()){
			var activity = activityGR.getDisplayValue('activity');
		}
	}
	
	email.setSubject(RITM.getValue('number') + " " + activity);

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

 

find_real_file.png

 

find_real_file.png

View solution in original post

10 REPLIES 10

Joe Taylor
Giga Guru

Kieran - you're a Wizard!

This script worked perfectly on my first try!!

I can't wait to see your article when you publish it.

 

Joe