- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 09:38 AM
Hi There,
I have variables on HR task. Once that HR task is completed then an approval email is triggered to get approval from the required parties. I want to print those variables in Approval email and need help with the mail script to pull those variables.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:15 PM
Update the script as follows.
var glideHRTask = new GlideRecord('sn_hr_core_task');
glideHRTask.addQuery('parent',current.getValue('sys_id')); //Assuming current is HR Case from where email was triggered
glideHRTask.addQuery('short_description',<short description of your hr task>); //This will fetch a specifc HR task with matching description.
glideHRTask.query()
var first_name='';
if(glideHRTask.next()){
first_name = glideHRTask.variables.first_name.toString(); //assuming you have a first_name variable on the record producer
}
template.print('First Name'+first_name); //To print a line in email.
Hope this helps.
Please don't forget to mark this answer helpful and correct if it manages to address your requirement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 09:44 AM
@Simran321 Simply do a glide record to your HR Task in your mail script and access the variables as follows.
var glideHRTask = new GlideRecord('sn_hr_core_task');
var first_name='';
if(glideHRTask.get('<sys_id of your HR Task>'){
first_name = glideHRTask.variables.first_name.toString(); //assuming you have a first_name variable on the record producer
}
template.print('First Name'+first_name); //To print a line in email.
For more information on mail script please refer to https://docs.servicenow.com/en-US/bundle/tokyo-servicenow-platform/page/script/server-scripting/refe...
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:05 PM
Hi Sandeep,
Thanks for your reply. There is an HR case that triggers the approval. HR task is child task for this case. The variables are on this HR task. How do I reference this HR task from HR case

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:08 PM
Notification is on Approval table or HR case table?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:15 PM
Update the script as follows.
var glideHRTask = new GlideRecord('sn_hr_core_task');
glideHRTask.addQuery('parent',current.getValue('sys_id')); //Assuming current is HR Case from where email was triggered
glideHRTask.addQuery('short_description',<short description of your hr task>); //This will fetch a specifc HR task with matching description.
glideHRTask.query()
var first_name='';
if(glideHRTask.next()){
first_name = glideHRTask.variables.first_name.toString(); //assuming you have a first_name variable on the record producer
}
template.print('First Name'+first_name); //To print a line in email.
Hope this helps.
Please don't forget to mark this answer helpful and correct if it manages to address your requirement.