Script for wait for condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 08:28 PM
I have a wait for condition running in my workflow. I'm trying to get it to run based on a variable called 'start_date' in my catalog item. If the start date is equal to the current date. Then It has to wait for 1 Day to proceed for next task.
As the task condition is if 'start date' is yesterday then only it has to create a Task.
How can I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 09:29 PM - edited 04-19-2023 09:30 PM
Hi, use an if condition activity before your wait condition and write below code. Join the Yes part to wait condition. Please Mark Solved if this works.
answer = ifScript();
function ifScript() {
var gDate = new GlideDate();
if (current.variables.start_date == gDate)
return 'yes';
else{
return 'no';
}
}
Regards,
Chandresh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 10:11 PM
so the workflow should wait till the next date comes after start date
example: if start date is 20th April then it should wait till 21st April and then on 22nd it should continue?
if yes then do this in the workflow timer advanced script
var gdt = new GlideDateTime(current.variables.start_date);
gdt.addDays(1); // 1 day after
answer = gs.dateDiff(new GlideDateTime(), gdt, true);
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