We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to close a HR task from schduled script

divyav7
Tera Contributor

We have a custom workflow for life cycle event.

For exit we have a life cycle event case created 30 days before last working day, with HR tasks assigned to multiple teams for clearance along with a task for manager clearance. Once the HR task is closed by team or manager from portal it creates a closed complete HR case with the record producer form variables.

The issue is, while I am trying to close manager task after setting variable value on the last working day from scheduled job, only the HR task is closed and HR case is not created under le case created for that employee's clearance.

var emp = new GlideRecord('sn_hr_core_profile');
emp.addEncodedQuery('employment_end_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
emp.query();
while (emp.next()) {
    var existingcase = new GlideRecord('sn_hr_le_case');
    existingcase.addEncodedQuery('stateIN10,18,3^subject_person=' + emp.user);
    existingcase.query();
    if (existingcase.next()) {
        gs.info("Existing HR cases" + existingcase.sys_id);
        var manager_task = new GlideRecord('sn_hr_core_task');
        manager_task.addQuery('parent', existingcase.sys_id);
        manager_task.addQuery('state', 'IN', '10,18');
        manager_task.query();
        if (manager_task.next()) {
                manager_task.variables.percentage_rating = '100';
                manager_task.state = '3';
                manager_task.update();
}
}
}

Not sure what I have missed, Please guide me how to close HR task, that triggers created for HR case that is marked as closed complete

0 REPLIES 0