Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Aman Kumar S
Kilo Patron

Hey,

Why don't your use eventQueueScheduled function in a run script, and pass the end datetime field as 5th parameter, and create a script action to create the task, it will trigger the event exactly at that time and your script action will create.

Below link explains about scheduled event

GlideSystem | ServiceNow Developers

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

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

Would I need to convert the 'end_date' value to a 'date/time' value?

Hello Mathew,

 

The variable i selected was a date and time and i added a timer activity before the catalog task creation and it works as expected.

find_real_file.png

find_real_file.png