ServiceNow Workflow Activity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 03:38 AM
Hi All,
I want to run an activity in ServiceNow workflow once time mentioned by the requester in the ticket in variable (Time and Date to remove access) is passed.
Which activity i have to use and how to compare that time with current time. Please guide. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 03:46 AM
Hi @Nikita50
How and where you are capturing the time ? is it in variables? then get the variable and compare with current date and time.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 03:54 AM
Hi AG,
Yes, date is provided in a date an time variable (Catalog variable)
(function executeRule(current, previous /*null when async*/) {
var requestedTime = current.variables.requested_time; // Replace with your variable name
var currentTime = new GlideDateTime();
// Convert requested time to GlideDateTime
var requestedDateTime = new GlideDateTime(requestedTime);
// Check if current time is greater than or equal to requested time
if (currentTime.compareTo(requestedDateTime) >= 0) {
return true; // Condition met
} else {
return false; // Condition not met
}
})(current, previous);I am using this script but it is stuck in running even when time is passed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 03:50 AM - edited 01-02-2025 04:05 AM
Hi @Nikita50 ,
you can use Wait for condition activity with script as follows
var currentTime = new GlideDateTime();
var varTime = new GlideDateTime('2025-01-02 11:46:00');
if(varTime.compareTo(currentTime)<=0)
answer=true;
replace varTime = new GlideDateTime(current.variables.dateTimeVar_name
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 03:55 AM
Hi Chaitanya,
Yes, date is provided in a date an time variable (Catalog variable)
(function executeRule(current, previous /*null when async*/) {
var requestedTime = current.variables.requested_time; // Replace with your variable name
var currentTime = new GlideDateTime();
// Convert requested time to GlideDateTime
var requestedDateTime = new GlideDateTime(requestedTime);
// Check if current time is greater than or equal to requested time
if (currentTime.compareTo(requestedDateTime) >= 0) {
return true; // Condition met
} else {
return false; // Condition not met
}
})(current, previous);I am using this script but it is stuck in running even when time is passed.
