Record Producer variables not showing in Email Notification

MBarrott
Mega Sage

Had a look and this seems to have been an issue many have had. 

 

I'm currently using a mail script which is working for all other task records (sc_task and inc) when they are assigned to an ITIL user to work through, but records that were created via a record producer come up empty. 

 

The actual fields are being utilized such as short_description which is puzzling me since I'd think they would pull like normal.

 

Any help would be much appreciated.  

 

Script Below:

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

          // Add your code here
		for (var key in current.variables)
		{
			var v = current.variables[key];
			if(v && v.getDisplayValue() != 'false')
			{
				template.print(v.getGlideObject().getQuestion().getLabel() + " " + v.getDisplayValue() + " <br>");
			}
		}
		
		template.print('<hr/>');

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

 

 

1 ACCEPTED SOLUTION

@MBarrott 

Thanks for confirmation.

Now if you want to bring in RITM's variable on sc_task notification then use this in email script and it will work

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

	// Add your code here
	var ritmObj = current.request_item.getRefRecord();
	var variables = ritmObj.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/>");
		}
	} 
		template.print('<hr/>');

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@MBarrott 

the email script is on same table?

try this

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

	// Add your code here
	template.print('RITM Variables: <br/>');
	var variables = current.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);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar,

 

This unfortunately didn't work for any records created via the record producer. To answer your question, the email notification is on sc_task and the email script is on global application.

@MBarrott 

did you check question_answer table got populated when you submitted the record producer?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@MBarrott 

it worked for me.

1) I submitted record producer with target table as incident and it added records to question_answer table

2) I ran the script and it printed the variable values

var rec = new GlideRecord('incident');
rec.get('7818dce1db5e5e50727ee7dcd396196e');

var variables = rec.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 != ''){
			gs.info('  ' + label + " = " + value + "<br/>");
		}
	} 

AnkurBawiskar_0-1733409464814.png

AnkurBawiskar_1-1733409487977.png

 

AnkurBawiskar_2-1733409511798.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader