Shows how to link Business Hours (or other native logic) directly into Salesforce flows. Uses concepts already found in formula fields such as the $Flow.InterviewStartTime global variable.
0:00 Intro - run only on business hours
0:15 Decision step: within business hours
0:30 End when false
0:40 Send email when true
0:50 Command: BusinessHours-IsWithin
1:05 Choose the name or ID
1:10 Set the interview start time
1:20 Test current weekday
1:35 Setting a custom test day
1:55 Test on specific weekend
2:05 Restore the interview start time
Here's a scheduled flow demo. But I want the schedule only on business days.
First we'll create an action called Within Business Hours and this is a Streamscript action. This action links flow with the Business Hours logic in Salesforce. And I'll come back in a second to fill it in. Next is the decision. I set the path to Run when the action returns true. Boolean equals true. Otherwise we will End the flow; this is the default when the decision is false. And I use the End step here just for the Run path. I will send an email using the Send email action and with a test message so that I know the flow runs.
Back to the Business Hours. I click on the action to edit the Streamscript, and it shows these standard Salesforce commands including Business Hours IsWithin so, using IsWithin, it has two parameters: Business Hours ID, and the Date/Time.
In setup, I have Business Hours for Eastern Standard Time.
It's Monday to Friday with some holidays configured already. I'll copy and paste the name or the ID will work too. Then I'll use the Flow Interview Start Time. That's a standard Flow global.
Now it's ready to test. Friday is a weekday, so this should run anyway.
Click Save, click Debug.
Let's look at the results. It decided that we're within Business Hours and it runs the left path and the email comes in.
But what I really want is to test it on a specific date. So let's create a new resource "now" and set its date to the 4th of February.
So that's hard coded as the 4th February for now.
To use the variable I'll edit Within Business Hours and I'll type in the date here.
It's ready to test again. The 4th February is a Saturday and is outside business hours.
Click Save and click Debug. It decided that we are outside business hours and stopped, which is good. As a final step, I'll update that variable to use the Interview Start Time.
So summing up: we needed a flow to run on business days. We used the native Business Hours logic in Streamscript. Then we used Date formulas to test the flow runs correctly. It decided that we are outside business hours and stopped, which is good. As a final step, I'll update that variable to use the Interview Start Time. So summing up: we needed a flow to run on business days; we used the native Business Hours logic in Streamscript; then we used Date formulas to test the flow runs correctly.
Getting started with Streamscript
Install from the Salesforce AppExchange
Package install link: