Script for wait for condition

Munna1
Tera Contributor

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?

2 REPLIES 2

Chandresh Tiwa1
Tera Contributor

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Munna1 

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. 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader