How can we trigger logic apps with different dates

Vijay-2791 151 Reputation points
2022-12-17T17:39:08.593+00:00

Suppose in my project they main 4 countries and they will Maintain SharePoint to upload the data so we can place that data in to adls but 1 country will maintain (4dec to 12dec)
2nd country maintain (2dec to 7th dec) 3country maintain (18th dec to 22 dec and 26th dec to 31dec) 4th country will maintain 12dec to 16th dec) all are maintained only one logic app how can I implement this scenario

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Ronen Ariely 15,206 Reputation points
    2022-12-17T18:07:25.557+00:00

    Hi,

    Option 1: add condition to execute the operations after the trigger which run on all dates. You can keep the information of countries and maintenance dates is Azure SQL and read it right after the trigger in order to check the condition.

    Option 2: Create separate apps.

    Option 3: use external scheduling system that rune the logic apps (for example using HTTP request).


  2. MayankBargali-MSFT 70,936 Reputation points Moderator
    2022-12-20T05:10:12.823+00:00

    @Vijay-2791 If you need to use the if condition then you need to proceed with Option 1 where your logic app will have timer trigger and based on the configuration it will be triggered every day.
    Now in different if condition you will be check if today's date (using utcNow function) falls under any of your below conditions. If yes, then add to the array variable.
    first country between 4dec to 12dec
    second country between 2nd dec to 7th dec
    third country between 18th dec to 22 dec and 26th dec to 31dec
    fourth country between 12dec to 16th dec

    As you have the array variable now you can loop through your business logic to execute the repeated step based on different county and their condition/logic.

    The better option would be creating a multiple logic app that will trigger based on your business condition dates and one signal logic app with HTPP trigger that accepts all the parameters that are needed to be executed by your workflow. Using this approach let's say if a new country is added in future or the time changes then it would be easy maintainable at your end.

    0 comments No comments

  3. Ronen Ariely 15,206 Reputation points
    2022-12-24T20:22:46.17+00:00

    Here is a full working example of using "condition" action

    Notice that I added only 2 conditions but you can add one for each company that you have

    273891-image.png

    The app run each day and in each execution I check as many conditions as I want. In my case I check of the day of the week is one then I execute the task - in my case the task is to add row to sql server table

    I also added condition to check of the day of the week is more than 3 and in this case i add the value to the table

    Here is the full code:

    {  
        "definition": {  
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",  
            "actions": {  
                "Condition": {  
                    "actions": {  
                        "Insert_row_(V2)_2": {  
                            "inputs": {  
                                "body": {  
                                    "c": 1  
                                },  
                                "host": {  
                                    "connection": {  
                                        "name": "@parameters('$connections')['sql']['connectionId']"  
                                    }  
                                },  
                                "method": "post",  
                                "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('default'))},@{encodeURIComponent(encodeURIComponent('default'))}/tables/@{encodeURIComponent(encodeURIComponent('[dbo].[TableName]'))}/items"  
                            },  
                            "runAfter": {},  
                            "type": "ApiConnection"  
                        }  
                    },  
                    "expression": {  
                        "and": [  
                            {  
                                "equals": [  
                                    "@variables('MyDay')",  
                                    1  
                                ]  
                            }  
                        ]  
                    },  
                    "runAfter": {  
                        "Initialize_variable": [  
                            "Succeeded"  
                        ]  
                    },  
                    "type": "If"  
                },  
                "Condition_2": {  
                    "actions": {  
                        "Insert_row_(V2)_3": {  
                            "inputs": {  
                                "body": {  
                                    "c": "@variables('MyDay')"  
                                },  
                                "host": {  
                                    "connection": {  
                                        "name": "@parameters('$connections')['sql']['connectionId']"  
                                    }  
                                },  
                                "method": "post",  
                                "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('default'))},@{encodeURIComponent(encodeURIComponent('default'))}/tables/@{encodeURIComponent(encodeURIComponent('[dbo].[TableName]'))}/items"  
                            },  
                            "runAfter": {},  
                            "type": "ApiConnection"  
                        }  
                    },  
                    "expression": {  
                        "and": [  
                            {  
                                "greater": [  
                                    "@variables('MyDay')",  
                                    3  
                                ]  
                            }  
                        ]  
                    },  
                    "runAfter": {  
                        "Initialize_variable": [  
                            "Succeeded"  
                        ]  
                    },  
                    "type": "If"  
                },  
                "Initialize_variable": {  
                    "inputs": {  
                        "variables": [  
                            {  
                                "name": "MyDay",  
                                "type": "integer",  
                                "value": "@int(dayOfWeek(utcNow()))"  
                            }  
                        ]  
                    },  
                    "runAfter": {},  
                    "type": "InitializeVariable"  
                }  
            },  
            "contentVersion": "1.0.0.0",  
            "outputs": {},  
            "parameters": {  
                "$connections": {  
                    "defaultValue": {},  
                    "type": "Object"  
                }  
            },  
            "triggers": {  
                "Recurrence": {  
                    "evaluatedRecurrence": {  
                        "frequency": "Second",  
                        "interval": 20,  
                        "timeZone": "Israel Standard Time"  
                    },  
                    "recurrence": {  
                        "frequency": "Second",  
                        "interval": 20,  
                        "timeZone": "Israel Standard Time"  
                    },  
                    "type": "Recurrence"  
                }  
            }  
        },  
        "parameters": {  
            "$connections": {  
                "value": {  
                    "sql": {  
                        "connectionId": "/subscriptions/9be5b21d-3676-40f1-baec-16c10ae909ec/resourceGroups/qq/providers/Microsoft.Web/connections/sql-1",  
                        "connectionName": "sql-1",  
                        "id": "/subscriptions/9be5b21d-3676-40f1-baec-16c10ae909ec/providers/Microsoft.Web/locations/centralus/managedApis/sql"  
                    }  
                }  
            }  
        }  
    }  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.