Populating field data from the sysapproval record for sysapproval_approver records

Erik Stuer
Tera Guru

I am struggling with an email notification that triggers off the sysapproval_approver table. I created an email script that queries the table that the approval is for (found in the sys_approval field of the approval form). I want to take a couple of the the fields from this record (its from a custom form for this specific use) and populate them dynamically into the email notification. Currently, the email body comes up blank where the email script is when testing. Here is the email script I am using currently.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var sysApproval = current.sys_approval;
var customRecord = new GlideRecord('u_custom_table');
customRecord.addQuery('number', sysApproval);
customRecord.query();
if (customRecord.next()) {
template.print("Opened by: " + customRecord.opened_by);
template.print("Purpose of Change: " + customRecord.u_purpose_of_change);
}
})(current, template, email, email_action, event);
I am wondering if the current.sys_approval I am trying to use to query the number field of my custom table is my problem. Or maybe I am screwing up the print part of it. Any help would be greatly appreciated. I have been running around in circles on this one.
1 REPLY 1

Zach Koch
Giga Sage
Giga Sage

In your mail script, I would use gs.info(current.sys_approval) to see what value you are getting vs what you expect in the system logs. Repeat that for any needed values until you are sure you know what you are getting. Work you way down the script logging values as needed and ensuring the log statement is firing, ensuring your script hasn't broken up to the log statement each time.

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!