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.

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

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

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

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
Mega 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.