Run Recurrence trigger in Azure Logic App on the Last day of Every Month
Asked Answered
B

3

5

I have an Azure Logic App which needs to run every month. I'm using a Recurrence Trigger to trigger my logic app. I want to run my Logic App only on the last day of every month. Eg. --> Jan 31st 2020, Feb 29th 2020, March 31st 2020, so on & so forth till Dec 31st 2020. Then same for year 2021.

Any idea on this can be achieved. Thanks!

Balfore answered 6/11, 2020 at 8:51 Comment(0)
F
2

For this problem, I think there are two options to choose. I describe both of them detail below:

1. You can set the "Recurrence" like below screenshot. enter image description here

Set the "Interval" and "Frequency" as every month and set the "Start time" from 2020-12-01T00:00:00Z. Then the trigger will be triggered at the beginning of next month and then triggered every month (here assume that the first second of the month is the last second of previous month).

Please not: I'm not sure if the "Recurrence" trigger in logic app works with cron expression in backend. So we don't know the next trigger will happen on the first day of next month, or happen on the day after 30 days(just add 30 days). As the time span is one month, so I can't test the result now. If you want to know the accurate answer, you can raise a support ticket on azure portal to ask Azure support team.

2. Set the logic app trigger by "When a HTTP request is received". You do not need to define any other configuration such as request body... Just need to create the trigger like below screenshot. enter image description here

Then create a Azure function with timer trigger. When you create the function, please set the cron expression as 0 0 0 1 * * like below screenshot. enter image description here

The cron expression means the function will be triggered every 1st of month (at 00:00:00).

Then in your timer trigger function code, modify the code to:

using System;
using System.Net.Http;

public static void Run(TimerInfo myTimer, ILogger log)
{
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

    HttpClient client = new HttpClient();

    client.PostAsync("copy the trigger url of your logic app here", null);

}

Save the function, the function will be triggered every first day of month(at 00:00:00). In function code, it will request the url of your logic app to trigger the logic app.

By the way, when you create the azure function app, you can choose "Consumption plan" then you will not pay much money for the function.

Foliage answered 9/11, 2020 at 1:45 Comment(0)
W
4

Accepted answer does not work.

Solution from Microsoft documentation by going into code view and setting trigger json also is not working, the LA was never being triggered.

However there is more elegant solution: I had to set up LA to run daily and added a simple if condition with the expression below, which was working as expected and you can even set up hour on which you want your LA to be executed:

Trigger setup Trigger settings

Condition text: @equals (dayOfMonth(addDays(utcNow(), 1)), 1)

Wellappointed answered 1/11, 2021 at 10:30 Comment(0)
B
2

Create a Logic App that runs every day. If its the "right" day, have it execute the Logic App that does the real work.

Alternatively, see this:

https://github.com/MicrosoftDocs/azure-docs/issues/26707

Brendabrendan answered 6/11, 2020 at 16:55 Comment(0)
F
2

For this problem, I think there are two options to choose. I describe both of them detail below:

1. You can set the "Recurrence" like below screenshot. enter image description here

Set the "Interval" and "Frequency" as every month and set the "Start time" from 2020-12-01T00:00:00Z. Then the trigger will be triggered at the beginning of next month and then triggered every month (here assume that the first second of the month is the last second of previous month).

Please not: I'm not sure if the "Recurrence" trigger in logic app works with cron expression in backend. So we don't know the next trigger will happen on the first day of next month, or happen on the day after 30 days(just add 30 days). As the time span is one month, so I can't test the result now. If you want to know the accurate answer, you can raise a support ticket on azure portal to ask Azure support team.

2. Set the logic app trigger by "When a HTTP request is received". You do not need to define any other configuration such as request body... Just need to create the trigger like below screenshot. enter image description here

Then create a Azure function with timer trigger. When you create the function, please set the cron expression as 0 0 0 1 * * like below screenshot. enter image description here

The cron expression means the function will be triggered every 1st of month (at 00:00:00).

Then in your timer trigger function code, modify the code to:

using System;
using System.Net.Http;

public static void Run(TimerInfo myTimer, ILogger log)
{
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

    HttpClient client = new HttpClient();

    client.PostAsync("copy the trigger url of your logic app here", null);

}

Save the function, the function will be triggered every first day of month(at 00:00:00). In function code, it will request the url of your logic app to trigger the logic app.

By the way, when you create the azure function app, you can choose "Consumption plan" then you will not pay much money for the function.

Foliage answered 9/11, 2020 at 1:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.