Need catalogue task to generate when the selected end date is reached in hour and date

matthew_hughes
Kilo Sage

I've got a catalogue item where I want the catalogue task to be created at exactly the date and time of the selected 'end date'. In my workflow, I've got a timer that uses the following code that waits for the selected 'end date' to be reached.

//Wait for End Date to be reached
// Set 'answer' to the number of seconds this timer should wait
answer = gs.dateDiff(gs.nowDateTime(), current.variables.end_date, true);
gs.info('For remove device, the date and time for now is' + gs.nowDateTime() + ' and for end date is ' + current.variables.end_date);

However, what I've noticed is that the catalogue tasks are being created on the selected 'end date' as soon as it goes to midnight:

find_real_file.png

 

I was just wondering if there is a way of amending it so that it creates the catalogue task on the date and the time when selected rather than at midnight.

 

The 'end date' variable is a 'Date' type variable.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

try this

//Wait for End Date to be reached
// Set 'answer' to the number of seconds this timer should wait
answer = gs.dateDiff(gs.nowDateTime(), current.variables.end_date.getDisplayValue(), true);
gs.info('For remove device, the date and time for now is' + gs.nowDateTime() + ' and for end date is ' + current.variables.end_date);

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Thanks very much. That now creates the tasks when the date and time are reached on the end date

@matthew.hughes@lloydsbanking 

Please check my below comments.

Regards
Ankur

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

@matthew.hughes@lloydsbanking 

Did you mistakenly marked other response as correct?

The answer marked as correct is exactly the same what I mentioned 3hours ago.

Would you mind marking my response as correct since that was the first correct response

Regards
Ankur

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

@matthew.hughes@lloydsbanking 

not required.

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

Hi @Ankur Bawiskar  What I have noticed is that it even though it's now working correctly, when I look the at logs, it's decreasing the value of the end date via 1 hour:

 

find_real_file.png

 

e.g. I selected the end date to be 18-05-2022 07:28:42, but it shows as 06:28:42