How to add Checklist type Template to HR Task

Ram141
Tera Expert

Hello All,

I got a requirement where Once Hr case is submitted we need to create HR Task automatically and need to attach the check list template based on the assignment group selected on HR case.

 

For That I have created Flow and the flow is triggering HR Task but Checklist is not getting attached to the task.

 

To attach the template I have chosen Template field on Create Task Action and written the below script , the logs are coming but template checklist didn't get attached.

 

Note: I have created the check list in 'sn_hr_core_template' table with HR task type as Checkllist.

 

The HR Task is getting created without errors but checklist is not getting attached.

Script Written In Template Field:

var assignmentgroup = fd_data.trigger.current.assignment_group;
//UK&IRE Payroll
gs.info('$$KN agmn grp ' + assignmentgroup);
if(assignmentgroup == '9279640c1b1a39d0ac16dce7b04bcb99'){
gs.info('UK grp');
var grObj = new GlideRecord('sn_hr_core_task');
grObj.initialize();
var t = new GlideTemplate.get('43c893fd1b927e547fd4eac7b04bcb02');
t.apply(grObj);
gs.info('templated applied');
}
//CE
else if(assignmentgroup == 'ccdd97da1bc27590726e99b2b24bcb5b'){
//fd_data.trigger.current.apply('Review_and_Approval_of_draft_payroll_reports_Payroll_CE');
//var sys_id_of_template1 = 'e64adb711bd27e547fd4eac7b04bcbad';
var grObj1 = new GlideRecord('sn_hr_core_task');
grObj1.initialize();
var t1 = new GlideTemplate.get('e64adb711bd27e547fd4eac7b04bcbad');
t1.apply(grObj1);
}

3 REPLIES 3

Kohei Tominaga1
Tera Expert

Hi, @Ram141 
You're likely encountering a timing issue between the HR Case's assignment group being set and your flow execution.

Here are the key points and recommendations:

  1. Verify HR Task's Template Field: After the task is created, manually check the "Template" field on the HR Task record. Is it populated with the expected template? This will tell us if your script thought it applied the template.

  2. Adjust Flow Trigger: Your flow might be running before the assignment_group on the HR Case is definitively set.

    • Recommendation: Change your Flow's trigger to run when the HR Case's Assignment Group field "changes to" or "is" the specific group you're targeting. This ensures the correct group is identified when your script executes.

This adjustment should help your checklist templates attach correctly.

sunilsargam
Kilo Sage

HI @Ram141 ,

 

You can add the checklist for the tasks using the HR Services. 

If you have the HR Service Created, you can open it and there would be related section which will allow you to add the checklist.

 

Let me know if this helps

Thank you

Sunil 

Anand2799
Kilo Sage

Hi @Ram141 ,

 

You need to update your script applied on Template field. You need to return the template sys_id.

Sample script:

var assignmentgroup = fd_data.trigger.current.assignment_group.toString();
//HR Tier 1
gs.info('HR Tier 1 ' + assignmentgroup);
if(assignmentgroup == '22d52c269f221200d9011977677fcf97'){
//Template 2
return 'f304b20e9356fe105f6bfef7dd03d68c';
}
else{
    //Template 4
  return "60c3cf4e93d6fe105f6bfef7dd03d6e7";
}

 

Thanks

Anand