Create a task based on a date within a Catalog Item

rachelconstanti
Mega Sage

I have a Service Catalog item with a "start date" variable.

I need the workflow associated to the catalog item to create a task 4 days after that "start date".

I would prefer to do this via scripting (which is not an area of expertise).

Any out there able to help with a script?

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

try below

var gdt = new GlideDateTime(current.variables.start_date);
gdt.addDays(4);
answer = gs.dateDiff(gs.nowDateTime(), gdt + ' 07:00:00', true);

View solution in original post

17 REPLIES 17

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Rachel,

so you want to wait till 4 days after start date; you can use workflow timer activity based on script

script below:

var gdt = new GlideDateTime(current.variable.start_date);

gdt.addDaysUTC(5);

answer = gs.dateDiff(gs.nowDateTime(), gdt, true);

whenever it begins the 5th day i.e. 00:00:00 the workflow would proceed and create the task; so I have added 5 days to the date variable

if you are in scoped application then gs.nowDateTime() won't work use this instead

new GlideDateTime() instead of gs.nowDateTime()

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur,

 

I am in the process of testing this now however I forgot to mention that the variable is part of a variable set.

Would I still use "var gdt = new GlideDateTime(current.variable.start_date);"?

Thank you!

 

Yes, It doesn't matter if variable is part of variable set.

That is what I thought however the "timer" I created in the workflow is getting skipped.  I am attaching the error (FYI - the variable is start_date).

I changed the "days" to 4.

The start date will be a Monday, the task needs to get created on Thursday.

 

 

there is a typo in calling variable . it should be 

current.variables.start_date