HRSD Activity Sets: How to Check Multiple Prerequisite Sets with OR Logic

SimenKnudsen
Tera Contributor

I'm working with ServiceNow HRSD and need to create an advanced trigger condition for an activity set that should trigger when either of two prerequisite activity sets has completed, rather than requiring both to be finished.

Current Setup

  • Module: ServiceNow HRSD
  • Context: Lifecycle Event activity sets for parental leave cases
  • Table: sn_hr_core_case_total_rewards
  • Requirement: Trigger when prerequisite Activity Set A OR Activity Set B is completed

The Challenge

The standard hrTriggerUtil.checkActivitySetsCompleted() method seems to require ALL activity sets in the provided array to be completed. However, I need OR logic where completion of either activity set should allow the trigger to proceed.

Current Approach

I've implemented this solution in my trigger condition script:

(function shouldActivitySetTrigger(parentCase, hrTriggerUtil) {
  // Separate checks for each prerequisite activity set
  var SET_A = 'activity_set_sys_id_1';
  var SET_B = 'activity_set_sys_id_2';
  
  var setACompleted = hrTriggerUtil.checkActivitySetsCompleted([SET_A]);
  var setBCompleted = hrTriggerUtil.checkActivitySetsCompleted([SET_B]);
  
  // Other business logic validation...
  
  // Return true if EITHER set is completed
  return setACompleted || setBCompleted;
})(parentCase, hrTriggerUtil);

Is this the correct approach for implementing OR logic with prerequisite activity sets in HRSD?
It is not triggering as I want it to 😞
Any ideas? Thank you.

1 REPLY 1

M Iftikhar
Mega Sage

Hi @SimenKnudsen

 

Your script is not working because the hrTriggerUtil utility is not available in the scope of an activity set's advanced trigger condition. The script runs against the parent case record, and you need to query the status of the activity set context records directly.

 

Try this script please:

(function() {
    // Paste the Sys IDs of your prerequisite activity sets here
    var activitySetSysIds = ['SYS_ID_OF_ACTIVITY_SET_A', 'SYS_ID_OF_ACTIVITY_SET_B'];

    // Query the activity set context table
    var grActivitySetContext = new GlideRecord('sn_hr_le_activity_set_context');
    
    // Filter for contexts related to the current case
    grActivitySetContext.addQuery('parent', current.getUniqueValue()); 
    
    // Filter for the specific prerequisite activity sets you are checking
    grActivitySetContext.addQuery('activity_set', 'IN', activitySetSysIds.join(','));
    
    // Filter for activity sets that are in the 'Closed Complete' state
    grActivitySetContext.addQuery('state', '3'); 
    
    grActivitySetContext.query();

    // The condition is met if the query finds at least one completed activity set
    // The .hasNext() method returns true if the query returned any records
    return grActivitySetContext.hasNext(); 
})();

Note: This script queries the sn_hr_le_activity_set_context table, which tracks the state of each activity set for your given case.

 

Hope this helps!

 

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.