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

Pritam6
Tera Guru

You will need to use Mail Scripts i.e. Scripting for email notifications



Take a look at the examples which should assist you - Example scripting for email notifications



You essentially need to query the Change Request and then use the script to "print" out the required information.



The mail script can then be called from within the Notification like so...${mail_script:script name}


Thanks for your reply -- I have zero knowledge of scripting but I'll see what I can do


Hi David,



I haven't tested this but should work to display the Change Request Start date and End date fields as an example.



<mail_script>


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


  var changeRequest = new GlideRecord('change_request');


  changeRequest.get(sysapproval.sys_id);


  template.print(changeRequest.start_date);


  template.print(changeRequest.end_date);


}


</mail_script>


Thank you, I will try this and see how I go - these are the fields I wish to bring across into the template from the change_request table into the template which is based on the sysapproval_approver table.



Comments and Work notes:



${comments_and_work_notes}



Planning:



Justification: ${justification}



Implementation plan: ${implementation_plan}



Risk and impact analysis: ${risk_impact_analysis}



Backout plan: ${backout_plan}



Test plan: ${test_plan}



Additional Details:



All Sites Affected: ${u_all_sites_affected}



Sites Affected: ${u_sites_affected}



Environment: ${u_environment}



What tests have been carried out prior to implementation?: ${u_tests_prior_implementation}



Are there any dependencies on other changes?: ${u_change_other_dependent}



Is the change focused on perimeter/DMZ based services?: ${u_change_focused}



Is the activity focused on the installation of a new appliance/service?: ${u_change_appliance_service}



Is there significant functional change in an existing appliance/service?: ${u_change_existing_service}



Communication Plan: ${u_communication_plan}



Is the request related to an incident?: ${u_related_incident}



Why is this an emergency change?: ${u_emergency_change_reason}