Scheduled Flow on Workdays

Mark Roethof
Tera Patron
Tera Patron

Hi all,

I am looking into slowly moving from Scheduled Jobs to Flow Designer. One of the things I can't figure out or might have overlooked... I would expect in Flow Designer just some choice list to appear where you could select a schedule 🙂

How to run a Flow only on workdays?

According to a certain schedule. Is that possible at all with Flow Designer? Or do we need to jump into scripting, Actions, etc. immediately for this... and making using Flow Designer instead of old school Scheduled Jobs actually less worthwhile?

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

1 ACCEPTED SOLUTION

Andrew Albury-D
Mega Guru

Hey Mark! 

I believe the best bet for this one is a custom action I've created to check if a given time is in schedule.

Create the flow with a "Daily" trigger, running every day at your desired time, then as the first action, check if the time the flow started (a data-dot from the trigger) is within a certain schedule. You could create a new schedule if you don't have one already.

Here's the details of the action:

Inputs: 
find_real_file.png

 

And the Script Step to check:

find_real_file.png

 

Here's the code snippet:

(function execute(inputs, outputs) {
	
  if (inputs.time) { 
    var timeToUse = new GlideDateTime();
    timeToUse.setDisplayValue(inputs.time.toString());
  } else {
    var timeToUse = new GlideDateTime();
  }
  
  var sched = new GlideSchedule(inputs.sched.getUniqueValue());
  var output = sched.isInSchedule(timeToUse);
  
  outputs.timeInSched = output;
  
  
})(inputs, outputs);

Then map the output to a true/false.

 

Then your flow will look like this:

find_real_file.png

 

 

Hope that helps!

-Andrew

View solution in original post

6 REPLIES 6

Mark Roethof
Tera Patron
Tera Patron

.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Andrew Albury-D
Mega Guru

Hey Mark! 

I believe the best bet for this one is a custom action I've created to check if a given time is in schedule.

Create the flow with a "Daily" trigger, running every day at your desired time, then as the first action, check if the time the flow started (a data-dot from the trigger) is within a certain schedule. You could create a new schedule if you don't have one already.

Here's the details of the action:

Inputs: 
find_real_file.png

 

And the Script Step to check:

find_real_file.png

 

Here's the code snippet:

(function execute(inputs, outputs) {
	
  if (inputs.time) { 
    var timeToUse = new GlideDateTime();
    timeToUse.setDisplayValue(inputs.time.toString());
  } else {
    var timeToUse = new GlideDateTime();
  }
  
  var sched = new GlideSchedule(inputs.sched.getUniqueValue());
  var output = sched.isInSchedule(timeToUse);
  
  outputs.timeInSched = output;
  
  
})(inputs, outputs);

Then map the output to a true/false.

 

Then your flow will look like this:

find_real_file.png

 

 

Hope that helps!

-Andrew

Ha Andrew,

Gnarly nice thought for an Action, all spot on! Only adding a default Schedule. Also gives immediate some ideas for more Actions about Schedules, adding days, etc.. With small generic Actions like these Flow Designer does make more sense than older techniques like Scheduled Jobs.

Tnx!

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn