We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

ServiceNow Workflow Activity

Nikita50
Tera Expert

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.

 

5 REPLIES 5

Dr Atul G- LNG
Tera Patron

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.

*************************************************************************************************************
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

****************************************************************************************************************

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.

Chaitanya ILCR
Giga Patron

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

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.