Try for free Book a demo

Decoding Logic App Dilemmas: How to Recurrence Trigger a Logic App at different hours and minutes?

Microsoft Azure

10 Mins Read

Azure Logic App Recurrence Trigger

Welcome again to another Decoding Logic App Dilemmas: Solutions for Seamless Integration! This time we will address another widespread problem which is to initiate the workflow at a different timeframe during the day or week with the same Azure Logic App Recurrence Trigger.  

Azure Logic App Recurrence Trigger

Of course, we want to accomplish this without replicating the same business logic in different Azure Logic Apps with different recurrence triggers – which would make it an absolute nightmare to maintain the solution properly; any change needed to be made to the business logic would have to be replicated n times across the different Logic Apps.

Problem: Trigger Logic App at different times during the day

Let’s assume we have a Logic App process that we want to run only during weekdays, which means from Monday to Friday, and each weekday, the Logic App needs to be triggered at 10:00 AM, 14:15 PM, 16:30 PM & 19:45 PM.

Again, we want to accomplish this without replicating the same business logic in different Logic Apps with different recurrence triggers.

Solution 1: Create a concept of receive port and receive locations using different Logic Apps

If you come from a BizTalk Server background, you are familiar with these terms: Receive Port and Receive Locations, and what we are going to try here is to apply these same principles in Logic Apps. But let me give you a little overview of what these are:

  • In BizTalk Server, a Receive Port is a logical entity representing a collection of one ore more receive locations. It serves as an entry point for receiving messages into the BizTalk Server environment – messages that can later be subscribed by a business logic, aka an Orchestration (equivalent to a Logic App in Azure).
  • A Receive Location, on the other hand, is a specific configuration within a Receive Port that defines the details of where and how messages will be received. Each Receive Location is associated with a specific transport adapter and has its own set of properties, such as the receive location address, polling interval, and message processing behavior.

By configuring multiple Receive Locations within a Receive Port, you can handle different message sources, such as file shares, FTP sites, message queues, or multiple scheduler triggers using different transport adapters or settings.

process for receiving and storing messages in the MessageBox database

Of course, we don’t have a MessageBox to do Pub-Sub or the same feature capabilities of BizTalk Server out-of-the-box, but that doesn’t mean we could not apply the same concept using different strategies:

  • The business process in the picture above will be our main Logic App, where we will implement all the required logic except for the recurrence trigger.
  • Our trigger logic apps will be the equivalent of the receive port, receive location, and MessageBox.

To accomplish this, first, let’s create our main Logic App, and do not forget to give it a proper name because you should know that one of the best practices you should have is to start using proper names from day one. To accomplish that, we need to:

  • Instead of using the recurrence as our trigger, let’s use the Request > When a HTTP request is received trigger. And leave the default settings.

Step 1 to Create a concept of receive port and receive locations using different Logic Apps

  • Right after the trigger, add a Response action – call it Async Response and let the default settings, i.e., Status code 200.

Step 2 to Create a concept of receive port and receive locations using different Logic Apps

  • Now on the Response action, click on … (3 dots), and select the option Settings.

Step 3 to Create a concept of receive port and receive locations using different Logic Apps

  • On the Setting for the ‘Async Response’ window, enable the option Asynchronous Response, and then click Done.

Step 4 to Create a concept of receive port and receive locations using different Logic Apps

  • Next, implement the required business logic – in our case, it is just a simple and basic logic to serve as a proof-of-concept.

Step 5 to Create a concept of receive port and receive locations using different Logic Apps

Now that we have our main process implemented, it is time to create our Azure Logic App Recurrence triggers – our receive locations:

  • Let’s start by creating the Recurrence trigger for 10:00 AM. That means creating a new Logic App – we will call it LA-RunOnSchedule10AM-POC – and Add a Recurrence Trigger that we will call: Recurrence Every weekday at 10AM
  • On the Recurrence trigger, set the following configurations:
    • On the Interval property, set to 1.
    • On the Frequency property, set to Week.
    • Click on the Add a new parameter option and add the following parameters:
      • On these days – this parameter is only available on Frequency Week.
      • At these hours
      • At these minutes
      • You can option also use the Time Zone parameter
    • On the On these days property, select the following days: Monday, Tuesday, Wednesday, Thursday, and Friday.
    • On the At these hours property, select the following hour: 10.
    • On the At these minutes property, set to 0 (zero).

Step 6 to Create a concept of receive port and receive locations using different Logic Apps

  • Next, add an Azure Logic App connector to call our main process.

Step 7 to Create a concept of receive port and receive locations using different Logic Apps

  • Now we need to create the same steps for the Recurrence trigger for 14:15 PM

Step 8 to Create a concept of receive port and receive locations using different Logic Apps

  • For the Recurrence trigger for 16:30 PM

Step 9 to Create a concept of receive port and receive locations using different Logic Apps

  • For the Recurrence trigger for 19:45 PM

Step 10 to Create a concept of receive port and receive locations using different Logic Apps

Note: you cannot have a single Scheduler with all the possible hours and minutes configurated something like this:

  • On the On these days property, select the following days: Monday, Tuesday, Wednesday, Thursday, and Friday.
  • On the At these hours property, select the following hours: 10, 12, 14, 19.
  • On the At these minutes property, set to 0,15,30,45.

Step 11 to Create a concept of receive port and receive locations using different Logic Apps

Because that means that it will run at 10:15, 10:25, 10:35, 10:45, 12:15, 12:25, 12:35, 12:45, 14:15, 14:25, 14:35, 14:45, 16:15, 16:25, 16:35, 16:45 on Monday, Tuesday, Wednesday, Thursday, Friday every week and this is not what we want, at least in this scenario presented.

Advantages of this solution

The main advantages of this solution are that:

  • The business logic is implemented only once, so we don’t need to make changes in multiple replicas of the business process. That will be easier to maintain and scale.
  • Scalability: because we have multiple Logic Apps that act as receive locations for the main business process, each with the trigger configured, it will be easier to scale or reconfigure without affecting the existing logic.

Disadvantages of this solution

The main disadvantages of this solution are that:

  • We need to create multiple Logic Apps, in this case, four Logic Apps, with only two actions to act as a receive port.
  • It can sometimes be challenging to read and understand all the overall logic since we have them separated across multiple Logic Apps, especially if you don’t organize your Logic Apps regarding resource groups and provide a good naming convention.

Above, I provided a scalable solution to this problem by implementing a concept of Receive Locations within Logic Apps. I also mentioned that one of the most significant disadvantages of that approach was the need to create multiple Logic Apps, which sometimes can be challenging to read and easily understand the overall implementation.

Now, I will discuss another approach that does not require the creation of multiple Logic Apps!

Solution 2: Apply Recurrence Trigger Conditions

The recurrence trigger can be very helpful in allowing us to trigger a Logic App in a specific Interval and Frequency.

It can be personalized to be fired in various ways, choosing the right frequency, which can be seconds, minutes, hours, days, weeks, and months, and then choosing the interval in which we want the recurrence to take place. But as lovely as it seems, it still has some limitations, and I want to show you how to overcome them, so to do that, let’s face a scenario.

As mentioned earlier if we have only one Scheduler in Logic App Recurrence Trigger with all the possible hours and minutes configurated something like this:

  • On the On these days property, select the following days: Monday, Tuesday, Wednesday, Thursday, and Friday.
  • On the At these hours property, select the following hours: 10, 12, 14, 19.
  • On the At these minutes property, set to 0,15,30,45.

Step 1 to Apply Recurrence Trigger Conditions

That will mean that the Logic App will be triggered at 10:15, 10:25, 10:35, 10:45, 12:15, 12:25, 12:35, 12:45, 14:15, 14:25, 14:35, 14:45, 16:15, 16:25, 16:35, 16:45 on Monday, Tuesday, Wednesday, Thursday, Friday every weekday and this was not the behaviour that we wanted, at least in this scenario presented.

So, the main question is: is there a way for us to overcome this situation? The answer is yes, there is. There is a small configuration trick that we can apply on our Azure Logic App Recurrence trigger that will allow us to have only one Logic App with a single trigger that will run the Logic App on the days and times we want:

  • Monday, Tuesday, Wednesday, Thursday, and Friday.
  • At 10:00 AM, 14:15 PM, 16:30 PM, and 19:45 PM.

Let’s recreate the main business logic that we have created in the previous blog post, but instead of using the Request > When a HTTP request is received trigger, we are going to use the Recurrence trigger.

  • On the Recurrence trigger, set the following configurations:
    • On the Interval property, set to 59.
    • On the Frequency property, set to Seconds.

Step 2 to Apply Recurrence Trigger Conditions

  • Next, and here comes the fun part, we are not adding any new parameters to the recurrence trigger as we did on the previous solution, but instead, we are going to apply a tweak by using a Trigger Condition. To do that, we need the following,

    • On the right side of the container, click on the … (three dots) and choose Settings:

Step 3 to Apply Recurrence Trigger Conditions

  • On the Settings for ‘Recurrence’ window, you will find out that you have a section named Trigger Conditions, so let’s add two conditions (expressions) that need to be true for the trigger to fire.

Step 4 to Apply Recurrence Trigger Conditions

  • On the Settings for ‘Recurrence’ window, under Trigger Conditions, click on + Add, and apply the following condition expression:

@or(equals(formatDateTime(addHours(utcNow(), 1), ‘HH:mm’), ’10:00′), equals(formatDateTime(addHours(utcNow(), 1), ‘HH:mm’), ’14:15′), equals(formatDateTime(addHours(utcNow(), 1), ‘HH:mm’), ’16:30′), equals(formatDateTime(addHours(utcNow(), 1), ‘HH:mm’), ’19:45′) )

  • On the Settings for ‘Recurrence’ window, under Trigger Conditions, click on + Add once again to apply the second condition expression:

@or(equals(formatDateTime(utcNow(), ‘dddd’), ‘Monday’), equals(formatDateTime(utcNow(), ‘dddd’), ‘Tuesday’), equals(formatDateTime(utcNow(), ‘dddd’), ‘Wednesday’), equals(formatDateTime(utcNow(), ‘dddd’), ‘Thursday’), equals(formatDateTime(utcNow(), ‘dddd’), ‘Friday’) )

Step 5 to Apply Recurrence Trigger Conditions

The first condition checks if the time is equal to the time described in the expression, and the second condition checks if the day is equal to the day described in the expression. If both expressions turn out to be true, the trigger is fired.

NOTE: we have addHours(utcNow(), 1 in the expression because of the summertime in our region. This can and should be adjusted to your own time. Or use a different Azure Logic App expression to address this daylight setting.

  • Then implement the required business logic – in our case is just a simple and basic logic to serve as a proof-of-concept.

Step 6 to Apply Recurrence Trigger Conditions

This trick will do the work, and now your Logic App will only be fired on the days and times you want it to be.

Advantages of this solution

The main advantages of this solution are that:

  • We only have one business logic implemented we all the logic. We don’t need multiple logic apps to act as triggers (receive locations)

Disadvantages of this solution

The main disadvantages of this solution are that:

  • As the previous one, reading and understanding all the overall logic can sometimes be challenging since all the trigger frequency is implemented as trigger conditions with complex expressions.

We can minimize this by adding the following comment to the trigger:

  • Trigger every weekday (Monday, Tuesday, Wednesday, Thursday, and Friday) at 10 AM, 14:15 PM, 16:30 PM, and 19:45 PM. See Trigger Conditions on Settings.

Step 6 to Apply Recurrence Trigger Conditions

The goal of this new series is to find common problems that people are facing with Logic Apps, either on StackOverflow, Logic App forums, Azure Logic Apps Microsoft Q&A, or any other source – feel free to provide ideas/problems you would like to be addressed – and provide a solution or solutions to that problem. At least I will add my point of view to address that issues. Of course, there may be other solutions; feel free to comment if that’s the case.

I hope you find this content useful and stay tuned for more Decoding Logic App Dilemmas.

This article was published on Jun 23, 2023.

Azure Logic Apps - Request Demo CTA

Related Articles