Activity Set - Advanced Trigger Condition

Leo Cris Ramos
Giga Expert

Hi, Community.

We have this requirement to set trigger condition for one of our activity set.

1. After closure of HRTASK

2. When Employee Number is not empty

3. if customField is set to false.

below is my script.

(function shouldActivitySetTrigger(parentCase /* GlideRecord for parent case */ ,
    hrTriggerUtil /* hr_TriggerUtil script include instance */ ) {
gs.info("Leo: Activity Set Execution");
var employeeNumber = parentCase.subject_person_hr_profile.employee_number;    
var customField = parentCase.subject_person.u_customField;
var templatesysID = gs.getProperty('sn_hr_le.templatesysID');

    //Complete HR Task
    var hrTask = new GlideRecord('sn_hr_core_task');
    hrTask.addQuery('parent', parentCase);
    hrTask.addQuery('template', templatesysID);
    hrTask.addQuery('state', 3);
    hrTask.query();
        if(hrTask.hasNext() && JSUtil.notNil(employeeNumber) && customField == false){
            gs.info("Leo: True");
            return true;
        }
    else{
        gs.info("Leo: False");
        return false;
    }

})(parentCase, hrTriggerUtil);

However, after completing the tasks, and the subject person profile has employee number and customField is set to false, it's always evaluating to false.

Can anyone help?

2 REPLIES 2

SumanthDosapati
Mega Sage
Mega Sage

Hi @Leo Cris Ramos ,

If you are sure that both employee number and custom field are correct then the first condition  hrTask.hasNext() might be false

Check having logs for these three conditions 

    hrTask.addQuery('parent', parentCase);
    hrTask.addQuery('template', templatesysID);
    hrTask.addQuery('state', 3);

And also you can put logs for  employeeNumber,  customField,  templatesysID these three declared variables and see what values they are printing.

 

Regards,

Sumanth

Hi, the script is working fine in background script execution it is returning true. However, we have decided to add a custom field instead in sys_user table to accompany all conditions only in one table. I have one more question, it would be great if you could check - https://community.servicenow.com/community?id=community_question&sys_id=3acc1ac61b701910aefc11751a4b...