Make Incident state to In-progress when on-hold and "waiting until" Date field was reached

Pratiksha KC
Tera Guru

Make Incident state to In-progress automatically when on-hold and "waiting until" Date field was reached for Europe/ Berlin Time zone. 

 

I have wrote the Scheduled Job script - Selected Timezone as - Europe/ Berlin

 

var gr = new GlideRecord('incident');
gr.addQuery('state', '3'); // On Hold
gr.addNotNullQuery('u_waiting_until');
gr.query();

while (gr.next()) {
    var holdUntil = new GlideDateTime(gr.getValue('u_waiting_until'));
    var now = new GlideDateTime();

    if (now.compareTo(holdUntil) >= 0) {
        gr.state=2; // In Progress
        gr.update();
    }
}
 
But it is not working. Should I have to convert UTC time zone to particular timezone ? 
Please guide me through this. 
 
Attached Screenshot for reference - 
PratikshaKC_0-1748546309288.png

 

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

And how are you running this? Because it has to run often to not having to wait until hours after the time is there. And yes, scheduled jobs can be tricky when it's with date/time calculation and timezones.

 

Why not just create a flow? I have done that over and over again with clients having the same requirement and it works perfectly.

Trigger it when 'u_waiting_until' changes and put a wait condition in there to wait until that time (the calculation is already done, because the flow will wait until exactly that moment, no matter the timezone). 
Then you do a check to see if the field is still the same (to prevent issues when it has been changed since the flow started). You can do that by setting a flow variable at the start of the flow, capturing the 'u_waiting_until' and check if the current field on the ticket is still the same as the flow variable. If not, just end the flow and if so, you can move it to 'in progress'. In the example below we are using a flow variable to check on the field still being the same.

MarkManders_0-1748589220624.png

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

2 REPLIES 2

Mark Manders
Mega Patron

And how are you running this? Because it has to run often to not having to wait until hours after the time is there. And yes, scheduled jobs can be tricky when it's with date/time calculation and timezones.

 

Why not just create a flow? I have done that over and over again with clients having the same requirement and it works perfectly.

Trigger it when 'u_waiting_until' changes and put a wait condition in there to wait until that time (the calculation is already done, because the flow will wait until exactly that moment, no matter the timezone). 
Then you do a check to see if the field is still the same (to prevent issues when it has been changed since the flow started). You can do that by setting a flow variable at the start of the flow, capturing the 'u_waiting_until' and check if the current field on the ticket is still the same as the flow variable. If not, just end the flow and if so, you can move it to 'in progress'. In the example below we are using a flow variable to check on the field still being the same.

MarkManders_0-1748589220624.png

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders 

 

I'll try to create flow instead of schedule job. Thanks for suggestion.