Execute Timer based on difference of two dates in Flow Designer

Anubhav24
Mega Sage
Mega Sage

Hi All,

 

I have a form for a catalog item which has two dates start and end , and based on the difference of these two dates I need to execute a timer in flow designer.

Where do I need to calculate the difference of these two dates like where will I write the script and then how to run a timer ?

 

Thanks in advance.

6 REPLIES 6

aryanjain25
Giga Guru

Hi @Anubhav24 , we have a "Wait For" functionality in flow designer where you can set custom duration to wait. 

Please refer the below documentation for better understanding. 

 

aryanjain25_0-1727259863257.png

 

 

https://docs.servicenow.com/bundle/xanadu-build-workflows/page/administer/flow-designer/concept/flow...  

 

I would appreciate if you can mark this response as correct or helpful if it helped you with your question.

 

Thanks,

Aryan Jain

dhanrajb
Tera Guru

Hi @Anubhav24 ,

 

You can achieve this with the below logic. But I'm not sure, how comfortable you are in creating a new variable.

1. Create a variable in the catalog item, which stores the difference between start and end. (Populate the different using onChange client script).

2. In Flow designer, retrieve duration value using Get Catalog variables action. 

3. Add Wait for duration flow logic, pass the value of duration using the Data Picker.

 

If you are not comfortable in creating variable, you can make use of g_scartchpad to do so. But g_scratchpad will be more complex.

 

Regards,

Dhanraj.

Creating another variable is fine but is there some approach in flow designer to do this , like adding a custom script action and then calculating the value of the date difference and then use that value but again that would be in a variable which will not be available as a data to be provided to wait for condition ? Correct me if I am wrong here.

Ummmm!! If you are approaching this way, still you can be able to pass the value to Wait for a duration flow logic. But the value being passed into that flow logic should be Duration Type. Something like in below picture.

dhanrajb_0-1727265254641.png

var startDate = new GlideDateTime('2024-09-08 09:00:00');
var endDate = new GlideDateTime('2024-09-09 10:00:00');
var diff = GlideDateTime.subtract(startDate,endDate);

 

Assign the value of "Diff" to the duration and directly assign the output to the flow logic. I'm pretty this works. But I'm just curious to know about making the flow wait for a long durations. Won't it affect the perfomance. 

 

Regards,

Dhanraj.