- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:27 AM
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:
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:43 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:41 AM
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 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:43 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 01:59 AM
Would I need to convert the 'end_date' value to a 'date/time' value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 02:13 AM