Pulling a field through from another table into a Notification email

davidreid
Kilo Contributor

Hello,

How would I pull a field through from one table into a notification template or email based on another table?

I'm trying to pull through the details of a Change Request (change_request table) and put them in an approval email template (sysapproval_approver table), and I'm not sure what the syntax would be to do this, I've tried various variations on ${table name.field name} but nothing seems to be working.

Any ideas?

1 ACCEPTED SOLUTION

Hi David,



Here you go, use the below. I've verified it works



var gr = new GlideRecord("change_request");


gr.get(current.document_id);


template.print("Start Date:" + gr.start_date + '<BR>');


template.print("End Date:" + gr.end_date);


View solution in original post

17 REPLIES 17

Hi Pritam,



Thank you for your help yesterday, I created this short script, but it doesn't seem to be pulling in any details.



The script is as follows.....



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


                  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


                  /* Optional GlideRecord */ event) {




                  // Add your code here





if(sysapproval.sys_class_name == 'change_request'){


  var changeRequest = new GlideRecord('change_request');


  changeRequest.get(sysapproval.sys_id);


  template.print("Start Date:" + change_request.start_date);


  template.print(change_request.end_date);


}




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



.... and I call it using the line ${mail_script:DR_get_change_details} in the template, but when I run my change process that generates the email based on this template, the section where the output from the script should be is blank when it needs to pull the details from the Change Request record that it relates to.



Do you know why it might not be working?



Thank you again for your help yesterday.


Hi David,



I noticed some typo's in your code... please try the below:



if(sysapproval.sys_class_name == 'change_request'){


  var changeRequest = new GlideRecord('change_request');


  changeRequest.get(sysapproval.sys_id);


  template.print("Start Date: " + changeRequest.start_date);


  template.print("End Date: " + changeRequest.end_date);


}


Hi there - thanks for this, I've made the change using your script but but I'm still not seeing any details of the change pulled through I'm afraid


Hi David,



Here you go, use the below. I've verified it works



var gr = new GlideRecord("change_request");


gr.get(current.document_id);


template.print("Start Date:" + gr.start_date + '<BR>');


template.print("End Date:" + gr.end_date);


Perfect! That works fine - I will add the other fields I want to pull through to that script and will confirm that all is well.



Thank you so much for all your help!