mail script that gets HR task variables to Approval email

Simran321
Tera Expert

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.

1 ACCEPTED SOLUTION

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.

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@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.

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

Notification is on Approval table or HR case table?

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.