Hi Colin,
Really cool use case! I think it is possible to achieve what you want without having to code a new Function :)
In fn_utilities v1.0.7 (
https://exchange.xforce.ibmcloud.com/hub/extension/2b6699ac8a3976b67dfbddee26dbe3a5) we released a new Function called: Utilities Timer::

By combining this Function with your script in a single Workflow like below, I feel you can achieve your use case:

Above we have set the Utilities Timer to sleep for 15m, after that 15m we call your script that does your time calculations and updates the fields as described in your post
Then in the Exclusive Gateway that follows the Script, we have a Script Condition that checks if the Incident is in an Open or Closed State. This condition will end the Workflow if the Incident is in a Closed state:

And for the other connector for that Exclusive Gateway we have "the opposite condition", that will continue to loop as long as the Incident is
not in a Closed state:

Finally, we would create a Rule that gets invoked on Incident Creation and targets this Workflow:

This method will start the Workflow on Incident Creation and keep looping every 15m until the Incident is Closed. Hopefully this method of using Timers with Looping in Workflows helps solve your issue...
------------------------------
Shane Curtin
Integrations Engineer - IBM Resilient
------------------------------
Original Message:
Sent: Fri July 05, 2019 07:32 AM
From: Colin Mattholie
Subject: Running a script from the integration server
Hi Shane,
I've tried using in product scripts and rules, but I encounter a constraint where I only appear to be able to update the record I'm in or the first one to meet the criteria. Not all records that meet the conditions. The full use case is simple it's SLA monitoring and notifications / alerting, this is stop gap until this hopefully arrives in V34.
So I'm writing out to two fields on a trigger, say when a phase starts (containment) the first being the date and time containment starts, I'm then calculating the second field based on the start value + the SLA time, then running a script to calculate the difference between the two, writing this value to a third field and popping this onto screen for an analyst, so they become aware of the time left. Unfortunately, I can't find away for force this to run an and update this field in the background. I've tried a rule without criteria, but this only works on the single open incident is updated.
I was trying to find away to force this to be updated, say every 15 minutes, so the timer counts down in the background and then when certain conditions are meet i.e. minutes left is less than, a notification could be sent within Resilient, to remind / escalate as required.
I've got it working perfectly in product manually, but obviously this isn't going to help customers if they receive a incident, don't update it for several hours and then when they do, they'll could get 5 alerts simultaneously telling them they're near the SLA and have now exceeded it as they've just updated the incident, that's not going to be helpful :-)
Any suggestions on how this could be achieved would be gratefully received.
Colin
------------------------------
Colin Mattholie
Original Message:
Sent: Fri July 05, 2019 05:11 AM
From: Shane Curtin
Subject: Running a script from the integration server
Hi Colin,
What is your full use case here? Could you give an example?
You may be able to achieve the outcome using the in In Product Rules + Scripts...
------------------------------
Shane Curtin
Integrations Engineer - IBM Resilient
Original Message:
Sent: Thu July 04, 2019 06:53 AM
From: Colin Mattholie
Subject: Running a script from the integration server
I was wondering if anybody has been able to, from the integration server, run a script periodically (CRON Job) to check the status of all incidents in an org and then based on one or more criteria i.e. last updated, incident status and phase, get the script to run against these selected records forcing a field to update?
------------------------------
Colin
------------------------------