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

Kieran Anson
Kilo Patron

Hi Joe,

When you say the notifications are being triggered from the sysapproval_approver table, is an approval record being created as part of a flow / workflow or are you using some sort of business rule to create an approval record?

Hi Kieran,

Yes.  The BR triggers an event called "RITM Approval" any time there is an approval step in any workflow.

The notification that runs is called "Approval RITM from Event" which is run from the sysapproval_approver table.

It is triggered if the "RITM Approval" event is fired.

So all of this is working.

I want the approval notification that goes out to HR to say something in the subject line like "Please approve the RITM001233 onboarding request for NEW EMPLOYEE"

(Where NEW EMPLOYEE is a string that is a the "legal_name" variable from the onboarding form.)

 

Joe

Is this firing the approval.inserted event? 

If so, you can create a new notification with a higher weight (i.e takes precedence) with a filter

find_real_file.png

Create a notification email script with the following script:

(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 name = RITM.variables.legal_name;
	
	email.setSubject('Employee Onboarding Approval for - ' + name);

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

find_real_file.png

Enter ${mail_script:employeeOnboarding} into the Message HTML section of your email. This will override the subject line.

find_real_file.png

 

Kieran - thank you! This mail script is exactly what I needed in my situation to have approval request notifications show 'Approval Request - RITM1111111 - Requested Item Name'

THANK YOU!!!