Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

(Manage Life Cycle Event) Activity Set is not getting triggered using Trigger Type: Advanced

Rohit_Singh_19
Tera Contributor

Hi All,

 

I am using advanced trigger type to check if the previous activity set is completed or not using the below script, along with the additional check in HR Profile (Parent Case->HR Profile->Custom Field). 

 

Expectation: If there is a value is the (Parent Case->HR Profile->Custom Field) I am straight away triggering the current Activity Set. If there is no value in the custom field then I am checking weather the previous Activity Set is competed or not. If completed then trigger the Current Activity Set.

 

var job_check = parentCase.subject_person_hr_profile.u_custom_field.toString();

if(job_check)
{
 return true;
}
else
{
             var prerequisiteActivitySetIds = ['sys_id'];   // SysId of Previous Activity Set
             if (!hrTriggerUtil.checkActivitySetsCompleted(prerequisiteActivitySetIds))
             {
      return false;
            }
            else
            {
            return true;
            }
}

 

The above configuration works when there is a value in the Custom Field it straight away trigger the current Activity Set and did not check if the previous activity set is completed or not. However when there is no value in the Custom Field, then even the previous Activity Set is completed the current Activity set is not getting triggered.

 

I also tried to just check the dependency on the previous activity set through script using below code but it didn't work. I have also cross check the sys_id of the previous activity set but still it's causing an issue.

 

var prerequisiteActivitySetIds = ['sys_id'];   // SysId of Previous Activity Set
if (!hrTriggerUtil.checkActivitySetsCompleted(prerequisiteActivitySetIds)){
return false;
}
else{
return true;
}

 

Thanks in Advace!

6 REPLIES 6

SANDEEP DUTTA
Tera Patron
Tera Patron

Hi @Rohit_Singh_19 ,

 

You can use the below code :

var job_check = '';
if (parentCase && parentCase.subject_person_hr_profile && parentCase.subject_person_hr_profile.u_custom_field) {
    job_check = parentCase.subject_person_hr_profile.u_custom_field.toString();
}

if (job_check) {
    return true;
}

var prerequisiteActivitySetIds = ['actual_sys_id_here']; // Replace with real sys_id
if (!hrTriggerUtil.checkActivitySetsCompleted(prerequisiteActivitySetIds)) {
    return false;
}

return true;

 

Thanks,
Sandeep Dutta

Please mark the answer correct & Helpful, if i could help you.

Hi @SANDEEP DUTTA ,

 

I tried your code but still it's not working.

Wessel van Enk
Tera Guru
Tera Guru

Hi @Rohit_Singh_19,

Did you try to put in into a function?

Example:

 

(function() {
    var jobCheck = '';

    if (current.parent && current.parent.subject_person_hr_profile) {
        var hrProfileGR = new GlideRecord('sn_hr_core_profile');
        if (hrProfileGR.get(current.parent.subject_person_hr_profile.toString())) {
            jobCheck = hrProfileGR.getValue('u_custom_field') || '';
        }
    }

    if (jobCheck) {
        return true;
    }

    var prerequisiteActivitySetIds = ['actual_sys_id_here']; // Replace with real sys_id(s)
    if (typeof hrTriggerUtil !== 'undefined' && hrTriggerUtil.checkActivitySetsCompleted) {
        return hrTriggerUtil.checkActivitySetsCompleted(prerequisiteActivitySetIds);
    }

    return true;
})();

Hi @Wessel van Enk 

 

The issue which I have observed is that when I tested only for 1st Activity Set dependency through script then also the code not working as expected. I did used gs.info to debug in script section and every time I am getting a false value even my first task is completed. When I use  Trigger Type - Other Activity Type (1st Activity Set) then it works fine.

 

I have already cross checked the sys_id of 1st Activity Set.  

 

In the HR Case after closing the 1st task I did check the Activity Set Contexts UI Action the first step show in finished state.

 

Is there any possible issue which is causing  the issue?

 

Thanks