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

That resolved the issue with the error however the timer is not pausing.  

I created a test request using 09-09-2019 for the start date.  The task that I want to create 4 days after the start date got created.  It shoud not have been created until 09-13-2019.

Hi Rachel,

Can you test it with small duration such as 4 hours etc

If that is ok then the days part will also work

Regards

Ankur

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

rajneeshbaranwa
Giga Guru

You can use below : 

 

var gdt = new GlideDateTime(current.variables.start_date);
gdt.addDaysUTC(4);
var current_time_stamp = new GlideDatetime();
var today_date_time = new GlideDateTime(current_time_stamp.getDisplayValue());
if (today_date_time > gdt)
{answer = true;}

I get the attached error when using your provided script.

 

Please use GlideDateTime onnplace of GlideDatetime. t in time should be in caps.