Timer in workflow based on variable

GB14
Kilo Patron

I am trying to add Timer in the workflow and trigger 7 days before the return date. I tried "A date/time or Duration field" but the variable field is not available to select so I guess I need a script. Also, I went through a lot of posts but unable to find something similar and some didn't work. Any help with the script will be appreciated. 

Requirements are: 

We would like the workflow to trigger 7 days before the return date.
Variable Name "Start_Date"

Thank you 🙂

1 ACCEPTED SOLUTION

If it is date field than set time like. Also make sure you select date which is more than 7 days from now.

var gdt = new GlideDateTime(current.variables.Start_Date); 
gdt.addDaysLocalTime(-7);
answer = gs.dateDiff(gs.nowDateTime(), gdt + " 07:00:00", true);

View solution in original post

12 REPLIES 12

If it is date field than set time like. Also make sure you select date which is more than 7 days from now.

var gdt = new GlideDateTime(current.variables.Start_Date); 
gdt.addDaysLocalTime(-7);
answer = gs.dateDiff(gs.nowDateTime(), gdt + " 07:00:00", true);

Hello Mike,

Appritiate your assistance with this issue. 

The task didn't trigger 😞

Below is the screenshot. If I leave the scheduled fields blank then the task trigger immediately. 

 

 

find_real_file.png

 

Thanks Mike.
had to make a minor change and then the script worked. 

Thank you very much. How it will work if the start date is within 6 days? Do we need to add any If conditions?  

No, If the date is less then 7 days then it will skip the timer so no condition is needed.