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

Glad to hear it helped 🙂 

Joe Taylor
Giga Guru

This worked perfectly the first time Kieran!

 

I've seem numerous other posts for a similar question.

Perhaps you might want to consider writing a generalized solution for everyone struggling to pull RITM variables into notifications scrips.

 

Thanks so much!

 

Joe

Oh good idea Joe,

I'll add it to my list of articles I'm working on. Glad my solution worked!

Joe Taylor
Giga Guru

Kieran,

 

On a related matter, how can I customize the approval notification emails?

I want the subject line going to the approver to have the specific short description of the workflow activity instead of the overall RITM description.

So for instance, if my RITM short description is "Hardware Requests", and I have a group approval step in the workflow with the activity title of "Approve Laptop Requests", I'd like the approver to get an email with the subject line "Please Approve Laptop Requests", not "Please approve Hardware Requests".

Joe

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