How to trigger activity set from lifecycle event again? For Advanced trigger condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2019 09:24 AM
Dear Community,
I wrote a script, for the Advanced trigger condition in the activity set of a lifecycle event. After some tests (the script writes to the system log), I figured out that the script works fine and returns either True or False depending on the situation (Checking whether a checklist item is checked or not).
As far as I understood, the script triggers the activity set if it returns true. This is the case at the start (buying a Record Producer via Service Portal), but at this time the checklist item could not be checked by the assignee. So I need that the script runs again from time to time to check whether the conditions are met or not. In case they are met the activity set should be triggered.
I read now, that the trigger runs every four hours but it is not true in my case (as I figured out from the system log).
Do anyone know how I can make the script run again e.g. every 30 minutes?
Help would be highly appreciated.
Best Regards,
Max
PS: Merry Christmas 🙂
- Labels:
-
HR Service Delivery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2019 10:40 AM
The trigger of that advanced condition in the activity set is controlled by the (hidden) Evaluation Interval field. It is NOT recommended to decrease this value from 4 hours since this will directly impact the parallel process flows and the calculation that is done for this function. Decreasing the interval will exponentially increase the number of parallel process flows will will bring you to the limit faster if you are having lifecycle events that are open for extended periods of time.
That interval is not meant to be a trigger for more frequent workflows, just to expand on the reason why we recommend not to reduce this value.
Regards,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 08:36 AM
This was an absolute necessity for us to do, based on business requirements, but there were indeed no OOB ways to accomplish it, beyond lowering the evaluation interval. Changing the interval was not an option, because SN fails any activity set whose triggers are checked more than 2500 times (which occurs in just over a day, if you set the interval to 30 seconds).
ServiceNow was kind enough to provide us a suggestion for changing an OOB workflow that might accomplish what we needed, but we didn't want to customize such a significant workflow, so were looking for a solution that didn't modify any existing scripts/workflows.
I realized it was possible to reset the sys_trigger record, but to get there I had to work with different application scopes that I couldn't get to play nicely with one another via cross-scope permissions. So I created a single flow, with 2 actions in different scopes:
Flow: "Trigger Activity Sets"
- Trigger: Kind of hacky, but I created a boolean u_trigger_activity_sets field and set it to false. When it changes to true, this flow kicks off. The final step of the flow sets it back to false. This let me throw a quick UI Action on HR Cases that were lifecycle events, that would temporarily set this to true. Also, from list-edit, I could kick off multiple activity set checks.
- The flow then calls the following Flow Actions in this order:
Flow Action [Human Resources: Lifecycle Events] - "Get Activity Set Triggers"
- Input: sys_id of the triggering HR Case, "case_id"
- Output: "trigger" value from the single script step
- Script Step code:
(function execute(inputs, outputs) {
outputs.trigger = "";
var context = new GlideRecord ('sn_hr_le_activity_set_context');
context.addQuery('hr_case', inputs['caseid']);
context.query();
while (context.next()) {
var execut = new GlideRecord ('wf_executing');
var wfcontext = context.workflow_context;
execut.addQuery ("context", wfcontext);
execut.query();
while (execut.next()) {
if (execut.getDisplayValue('activity') != 'Wait to reevaluate Trigger Script')
continue;
var trig = new GlideRecord ('sys_trigger');
trig.addEncodedQuery("nameLIKE"+execut.context);
trig.query();
if (trig.next()) {
if (outputs.trigger != "")
outputs.trigger += ",";
outputs.trigger += trig.sys_id;
}
}
}
})(inputs, outputs);
That first action returns a comma-separated list of sys_trigger sys_ids, representing all the activity sets in the associated case that have yet to be triggered. They are put in this list regardless of whether they have 4 seconds left to trigger, or 4 hours. However, those sys_trigger records can only be modified from global scope, so the second action below is created in global:
Flow Action: [Global] - Fire "sys_triggers"
- Input: "trigger" (list of sys_triggers from previous action)
- Output: None -- the script step restarts all the triggers
- Script step:
(function execute(inputs, outputs) {
var trigs = [];
trigs = String(inputs['trig']).split(",");
for (var i=0; i<trigs.length; i++) {
var trig = new GlideRecord ('sys_trigger');
trig.get (trigs[i]);
var gdt = new GlideDateTime();
gdt.addSeconds(5);
trig.next_action = gdt;
trig.update();
}
})(inputs, outputs);
I know it's two years since the original question, but hope this helps someone!