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

@MBarrott 

can you explain how your record producer is linked with sc_task?

Ideally sc_task are created when someone submits catalog items.

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

Hi @Ankur Bawiskar - I apologize it is a catalog item not a record producer. For some reason the catalog item generated records aren't working correctly. 

 

I believe I have or am close to a fix, however. 

@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

Hi @Ankur Bawiskar - this script is working much better and pulling data.

 

The issue I'm seeing is that it is including empty non-mandatory fields from catalog items, labels, or checkboxes which are not select (displaying 'false' on the email).

 

This wasn't the case with the original script - weirdly enough at least one catalog item worked and displayed the info correctly. This was the only catalog item which had an approval tied to it which shouldn't make a difference in my opinion but is the only difference I can see. 

@MBarrott 

I hope I have provided sufficient response with sample scripts which should help you get across this.

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