DEV Community

Cover image for Data Source Environment Variables in Power Automate actions
Kinga
Kinga

Posted on

Data Source Environment Variables in Power Automate actions

Environment variables in Power Automate flows allow you to manage and reuse values across multiple flows, making updates easier and reducing hardcoding. They also simplify configuration management for different environments, enhancing flexibility and maintainability.

To create reference to a SharePoint site or a SharePoint list, you'd create environment variables of Data source type:

  • SharePoint site: Parameter type = Site, and choose a site from a drop down
  • SharePoint list or library: Parameter type =List, and choose a list/library from a drop down.

Let's use Compose action to quickly check the format they are stored in:

Image description

The site reference is stored as URL, but the list references are stored as GUID. It's of course reasonable, but may cause a bit of additional effort when you'll try to use them with Power Automate actions.

Referencing SharePoint in Power Automate

In Power Automate, different actions reference SharePoint lists and libraries differently.

Sometimes, it will be list Title, sometimes the URL (a.k.a. RootFolder), and other times, an Id.

When accessing document libraries using drives Graph API, the id is not in GUID format, but rather something like this: b!WqNS-yXl-EmB9E5tlOY2kP3B7PZTD8lCgoRdFoRzZnK_WYiyUTlZTptnb3lchjmk.

What better way to find out the required format than by trying. ๐Ÿ˜Š
SharePoint actions can be configured by selecting lists from a dropdown menu, and a test run of the flow provides the information we need.

1. SharePoint | Get items

Image description

In this case, the action is referencing lists using GUID. Great! The environment variable will work.

๐Ÿ’กReferences list using: GUID

2. SharePoint | Copy File

When copying files, you define the source and target locations by specifying a site, a library, and optionally, a folder. A quick peek into the executed flow reveals the format of the "File to Copy" and the "Destination Folder."

Image description

๐Ÿ’กReferences libraries using: URL

When a SharePoint list is created, its URL is automatically generated based on the site URL and the list name. When the list title is changed, its URL will always remain the same.

3. Excel Online (Business) | Run script from SharePoint library

The workbook and scripts are referenced using Site URL, the library's drive Id, (optionally folder name) and the file name.

Image description

๐Ÿ’กReferences libraries using: drive Id.

4. SharePoint | Send an HTTP request to SharePoint

This action requires you to define the URL, and how you reference a list depends on you.

_/api/web/GetById() expects GUID format meaning that environment variable will work also here.

Image description

๐Ÿ’ก References list using: GUID (or Title if you choose so)

5. HTTP with Microsoft Entra ID (preauthorized) | Invoke an HTTP Request

Using this action you may submit a request to any HTTP endpoint that supports Entra ID authentication. How you reference a list/library depends on the API you use.

Did you know? SharePoint REST API v2 is based on Graph API, and you can verify if Microsoft Graph REST API call is supported by SharePoint Online by adding $whatif at the end of your Graph API query.

๐Ÿ’ก References list using: GUID, Title, URL, drive Id

"Get Data Source List Info" Power Automate to the rescue

The "Get Data Source List Info" flow is designed to be executed as a child flow and accepts two parameters: the site URL and library/list Id, as provided by the environment variables.

It returns list information including:

  • list id: this is the value provided as List Idparameter,
  • drive Id: used by Graph API when referencing libraries,
  • list name: the RootFolder as developers know it; used in URL; it's generated automatically and cannot be changed by users (can be changed with PowerShell)
  • list title: this value can be changed by users; I'm never using it in my code to reference lists, but you may want to use it when sending notifications
  • absolute Url (the format of absolute URL differs between lists and libraries).

Retrieving information for a list

Retrieving information for SharePoint lists and libraries is executed exactly the same way. You simply provide the site and list environment variables.

Image description

The result will vary slightly between lists and libraries, because in Graph API lists cannot be accessed as drives . The absolute url is also different between lists and libraries:

Image description

Image description

Download the solution

You may download the workflow from the PowerAutomate-Get-Data-Source-List-Info github repository. You'll find both, managed and unmanaged solutions, under Releases.

The repo also provides additional information for installing and configuring the solution.

Top comments (0)