How to Schedule Flow to Run only on Weekdays (MON-FRI)

sumanthg
Tera Contributor

In ServiceNow Flow Designer, the scheduling options allow you to run flows daily, weekly, or monthly. However, there is no direct option to schedule a flow to run only on weekdays (Monday–Friday). This guide provides a simple approach to achieve this using a script step.

 

Steps to Implement:

 

1. Create a Custom Action:

 

Navigate to Flow Designer and create a new action.

 

This action does not require any inputs.

 

2. Add a Script Step:

 

Under the Inputs section, add a new Script Step.

sumanthg_0-1738131250266.png

3) Insert below script in your Script step

 --------------------------------------------------------------    

(function execute(inputs, outputs) {
// ... code ...
//Get the current date and time.
var now = new GlideDateTime();
// Get day of the week(1= Mon,...7= sat).
var dayOfWeek = now.getDayOfWeekLocalTime();
//check the day is weekday
var isWeekday =(dayOfWeek >=1 && dayOfWeek <= 5);
//set the output variable to true if it's weekday, false if it's a weekend
outputs.answer =isWeekday;
})(inputs, outputs);
--------------------------------------------------------------------------

4) Add Output variable below the script.

sumanthg_2-1738131491132.png

5)Navigate to the Outputs section, click on Edit Outputs, and define the output variable.

sumanthg_3-1738131631974.png

6)Then Click Exit Edit Mode and use the data pill to reference the script output

sumanthg_4-1738131757324.png

 

------------------------------------------------------------------------------

Open your flow and add the custom action after the trigger.

 

Use an If condition to check the isWeekday value.

 

If true → Proceed with your logic (e.g., create an incident).

 

If false → End the flow.

sumanthg_5-1738131842199.png

 

sumanthg_6-1738131925606.png

Test and Validate:

 

Run the flow to verify that it executes only on weekdays.

 

This approach ensures that your flow runs exclusively from Monday to Friday, preventing unnecessary executions on weekends. Let me know if you have any challenges implementing this!

has context menu

 

#flow

#Scheduleflow

#weekdays

 

0 REPLIES 0