How to give the two folder paths in when a file is created or modified trigger

Podili Vijay 20 Reputation points
2023-03-05T12:24:06.9533333+00:00

I'm able to give two paths in when a file is created or modified trigger.using below code @or(startsWith(triggerBody()['{Path}'], 'Shared Documents/source/'),startsWith(triggerBody()['{Path}'], 'Shared Documents/General/')) But my paths are Shared Documents/QUERY NEW/Country/PB/Actuals/QUERY Results/Mar-2023/QueryFeb_ 2023 QueryRefredhAs on 05032024 NOTE:Feb is the last month and my second expression is till Shared Documents/New/jack/2023/Mar/05-Mar/solution-v3 .xlsx so on the second path if we create the date month folder then also logic app will trigger how to avoid these case i want to trigger the logic app only when file is uploaded in the path. @MayankBargali-MSFT can any one know the answer

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

1 answer

Sort by: Most helpful
  1. Sonny Gillissen 3,751 Reputation points Volunteer Moderator
    2023-03-06T09:18:44.1233333+00:00

    Hi,

    I've tested your question in my test lab, and it works as expected. When I add the code you wrote to my trigger condition it only triggers when files are added in /General or /source (and subfolders), but not in other root folders.

    Just to make sure it's in the right place, I've set my trigger to fire on the root folder of my site collection, the clicked the "three dots" and selected "Settings":
    User's image

    Next I've added your code to the trigger condition:

    User's image

    For completeness, I've used this code:

    @or(startsWith(triggerBody()['{Path}'], 'Shared Documents/source/'),startsWith(triggerBody()['{Path}'], 'Shared Documents/General/'))

    It works as expected.

    I've added my Logic App code for your reference (you can copy/paste it but be sure to change the following details to your own (for the connection part you could also reuse from your current Logic App):

    • {SiteCollectionUrl} to your Site Collection's URL
    • {DocumentLibraryGuid} to your Site Collection's document library GUID
    • {SubscriptionId} to the Azure subscription ID of your Logic App and connection file
    • {ResourceGroupName} to the name of your Logic Apps' resource group
    • {Location} to the location your resource group is in
    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {},
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {
                "$connections": {
                    "defaultValue": {},
                    "type": "Object"
                }
            },
            "triggers": {
                "When_a_file_is_created_or_modified_(properties_only)": {
                    "conditions": [
                        {
                            "expression": "@or(startsWith(triggerBody()['{Path}'], 'Shared Documents/source/'),startsWith(triggerBody()['{Path}'], 'Shared Documents/General/'))"
                        }
                    ],
                    "evaluatedRecurrence": {
                        "frequency": "Minute",
                        "interval": 3
                    },
                    "inputs": {
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                            }
                        },
                        "method": "get",
                        "path": "/datasets/@{encodeURIComponent(encodeURIComponent('{SiteCollectionUrl}'))}/tables/@{encodeURIComponent(encodeURIComponent('{DocumentLibraryGuid}'))}/onupdatedfileitems"
                    },
                    "recurrence": {
                        "frequency": "Minute",
                        "interval": 3
                    },
                    "splitOn": "@triggerBody()?['value']",
                    "type": "ApiConnection"
                }
            }
        },
        "parameters": {
            "$connections": {
                "value": {
                    "sharepointonline": {
                        "connectionId": "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Web/connections/sharepointonline",
                        "connectionName": "sharepointonline",
                        "id": "/subscriptions/{SubscriptionId}/providers/Microsoft.Web/locations/{Location}/managedApis/sharepointonline"
                    }
                }
            }
        }
    }
    

    Please let me know if my answer is helpful, and if so click "Accept answer" and upvote it. Feel free to drop additional queries in the comments below.


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.