Trigger Workflow Timer 5 days before a specific Date/Time given in RITM variable value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-19-2024 07:21 PM
Hello Everyone,
Need one help.
I have a requirement to trigger a timer if current date is 5 days or less than estimated_end_date (which is a RITM variable).
Now this date is editable, that is, users can edit the variable value anytime.
In the workflow timer script, I have written the below code, but sadly the timer is not firing.
Can you please tell me where I am going wrong here.
Thanks in advance.
var diff = gs.dateDiff(gs.nowDateTime(), current.variables.estimated_end_date, true);
var days = diff / (24 * 60 * 60);
if (days <= 5) //if no. of days is 5 or less
answer = 0;
else
answer = 1000000; //an arbitrary large value if no. of days is more than 5
Please mark this post as a solution and also as helpful, if this resolves your issue or query.
Thanks,
Subhadeep Ghosh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-19-2024 07:51 PM
Script seems to be correct, Can you put some log and check :
var diff = gs.dateDiff(gs.nowDateTime(), current.variables.estimated_end_date, true);
var days = diff / (24 * 60 * 60);
gs.info("Days difference: " + days);
if (days <= 5) {
answer = 0;
gs.info("Timer should be set.");
} else {
answer = 1000000;
gs.info("Timer should not be set.");
}
Please Mark ā Correct if this solves your query and also mark šHelpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-19-2024 07:53 PM
HI @subhadeep1618 ,
I trust you are doig great.
Here's an updated version of your script with added debugging statements:
var estimatedEndDate = new Date(current.variables.estimated_end_date); // Parse estimated_end_date as Date object
gs.log("Estimated End Date: " + estimatedEndDate); // Log estimated end date for debugging
var diff = gs.dateDiff(gs.nowDateTime(), estimatedEndDate, true);
var days = diff / (24 * 60 * 60);
gs.log("Days difference: " + days); // Log days difference for debugging
if (days <= 5) {
answer = 0;
gs.log("Timer set to 0."); // Log timer set to 0 for debugging
} else {
answer = 1000000;
gs.log("Timer set to 1000000."); // Log timer set to 1000000 for debugging
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-19-2024 07:57 PM
@subhadeep1618 I'd suggest moving it into a flow, if it is not already.
Then all you need to do is add a wait for duration of time from the flow logic, similar to this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-19-2024 08:09 PM
user can change the variable anytime? That's not good.
How would the workflow determine this?
Please discuss with your customer when should this variable be edited and once filled make it readonly so that it updates only once
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader