At Compass 365, we’ve recently streamlined our approach to managing Power Automate flows by incorporating environment variables. This method allows us to perform different actions based on whether we’re in development (dev), testing (test), or production (prod) environments. A prime example of this is customizing email workflows to send different emails to different recipients depending on the environment. Here’s a breakdown of how this works.
Setting Up the Flow
In the video, Nikki from Compass 365 demonstrates a simple yet powerful Power Automate flow for sending Outlook emails. The key feature of this flow is its use of an environment variable to specify whether the current environment is dev, test, or prod. This variable determines the type of email being sent and the recipients.
Initializing Variables
The flow begins with initializing three variables:
- Email Recipients: Defines who will receive the email.
- Email Subject: The subject line of the email.
- Email Body: The content of the email.
Determining the Environment
Next, the flow determines the current environment using a SharePoint list called “People by Environment.” This list contains:
- A title field for the environment (dev, test, prod).
- A person field for selecting the email recipient.
A Get Items action retrieves the appropriate row from this list based on the environment variable.
Configuring the Email Content
The flow then sets up a switch case for the environment variable to customize the email subject and body based on the environment:
- Development (Dev): The email subject is prefixed with “(DEV)”.
- Testing (Test): The email subject is prefixed with “(TEST)”.
- Production (Prod): The email subject has no prefix since this is for end-users.
This prefixing helps developers and testers identify which environment an email is coming from, aiding in tracking and debugging.
Sending the Email
Finally, the flow sends the email using the configured variables. It ensures the email body is correctly formatted in HTML by switching the email view to HTML mode.
Practical Example
Nikki runs the flow three times, once for each environment value (dev, test, prod), and demonstrates the resulting emails:
- Development Email: Subject prefixed with “(DEV)”.
- Testing Email: Subject prefixed with “(TEST)”.
- Production Email: Subject without a prefix.
This approach highlights the flexibility and efficiency of using environment variables in Power Automate to adapt workflows dynamically.
Using environment variables in Power Automate flows provides a robust way to differentiate actions based on the current environment. This method is particularly useful for managing email workflows, ensuring that the right emails are sent to the right people with appropriate content and context. By standardizing this approach, teams can maintain consistency across development, testing, and production environments, enhancing workflow management and reducing errors.
We hope you found this overview helpful. For a detailed walkthrough, check out the video above by Nikki from Compass 365.
If you are new to the Power Platform or looking to expand your capacity in this exciting automation space, Compass365 can help. Explore our Power Platform Services or contact us to arrange for a complimentary consultation.
Compass365, a Microsoft Gold Partner, delivers SharePoint, Microsoft Teams and Power Platform solutions that help IT and Business leaders improve the way their organizations operate and how their employees work.