environment-variablespower-automatepowerapps

How to Use Dynamic Environment Variables in Power Automate Trigger for SharePoint File Creation?


I am trying to create a Power Automate flow that triggers when a file is created in a specific folder within a SharePoint site. The trigger I am using is "When a file is created (Properties only)", and it works perfectly when I provide the inputs as fixed values for:

  1. SharePoint site address

  2. Library name

  3. Folder path

However, I need to make these inputs dynamic to allow flexibility across environments. Here's what I've done so far:

  1. Created environment variables for the SharePoint site address, library name, and folder path.

  2. Added these environment variables to a solution in Power Automate.

  3. Configured the flow within the solution to use these environment variables for the trigger inputs.

After these changes, the flow does not trigger when I add a new file to the specified folder.

What I’ve Tried:


Solution

  • It's not as simple as it otherwise looks. If you want to see what values the environment variables should have, you need to configure the trigger with the static values provided to you in the drop downs first ...

    Static Values

    ... and then from there, you need to navigate to the Code view where it will give you the actual values the operation expects.

    In the case of that trigger, the Library Name will be your problem. It expects the GUID of the drive ID, not the name itself.

    For the above image, this is how my Code view looks ...

    {
      "type": "OpenApiConnection",
      "inputs": {
        "parameters": {
          "dataset": "https://xxx.sharepoint.com/sites/TestSite",
          "table": "8b487360-db75-4cb9-86c1-a94ad87d5971",
          "folderPath": "/Shared Documents/General"
        },
        "host": {
          "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline",
          "connection": "shared_sharepointonline",
          "operationId": "GetOnNewFileItems"
        }
      },
      "recurrence": {
        "interval": 3,
        "frequency": "Minute"
      },
      "splitOn": "@triggerOutputs()?['body/value']"
    }
    

    Site Address = dataSet

    Library Name = table

    Folder = folderPath

    ... you can see the Site Address and Folder are straight strings so you can supply those as is but the Library Name is not and that's what you'll need to take care of.