Environment variables in Power Apps are essentially key-value pairs that store configuration settings, which can be used across different components within your Power Platform solutions. They offer a flexible and efficient way to manage parameters that might change between environments (like development, testing, and production) or need to be updated without modifying the actual app or flow logic.

OBJECTIVE:

To create SharePoint folders when a specific field in a table changes, utilizing environment variables to store folder names. The process should check if each folder exists, and if not, create the root folder for the selected record.

Steps to Implement:

Step 1: Store Folder Names in Environment Variables.

  • Within the solution, click on New and select Environment Variable
  • Create an environment variable for storing the folder names
  • Name: FolderNames
  • Data Type: Text
  • Value: Work Permit;Bank Account;P-Tal
  • Save the environment variable.

fig.1

Step 2: Trigger Power Automate Flow on Field Change.

  • Create a field and this field should be a Boolean field indicating whether to create the SharePoint folders.

fig.2

  • Create a Power Automate flow that triggers when the ‘Create SP Folders’ field in the Employee table is set to ‘Yes’

Flow Details

1) Trigger: When a row is modified in Dataverse.

2) Initialize variable

  • Name: FolderNames
  • Type: String
  • Value: Use the dynamic content picker to select the Folder Names environment variable.

3) Compose:

  • Inputs: split(variables('FolderNames'), ';')

4) Initialize variable

  • Name: EmployeeFullName
  • Type: String
  • Value: Use the dynamic content picker to select the value in our case (Fullname) of the record.
    @triggerOutputs()?['body/fullname']

5) Apply to each (Output of Compose)

  • Click on “Add an action” inside “Apply to each”

a) Get files (properties only) SharePoint

  • Site Address: Your SharePoint site URL
  • Library Name: Your document library
  • Filter Query:FileLeafRef eq '@{items('Apply_to_each')}' and FileDirRef eq '/sites/yoursite/Shared Documents/@{variables('EmployeeFullName')}'

b) Condition action

length(body('Get_files_(properties_only)')?['value'])

  • Condition: If length “is equals” to “0”,
  • Inside the “If yes” branch of the condition, click on “Add an action

c) Create new folder SharePoint

  • Site Address: https://yoursharepointsite
  • List or Library: Documents
  • Folder Path: @{variables('EmployeeFullName')}/@{items('Apply_to_each')}

Make sure to replace yoursite and Shared Documents with the actual site and document library names you are using.

fig.3

OUTPUT:

This flow will ensure that folders are created in SharePoint whenever the ‘Create SP Folders’ field is set to “Yes” for a record.

fig.4

Hope it helps!