Power Automate: Instant Low-Code Plugins To Run PowerFx Code
Power Automate: Instant Low-Code Plugins To Run PowerFx Code Posted by - Matthew Devaney on - October 27, 2024 16 Comments Power Automate can run PowerFx cod...
- Published
- Reading time
- 6 min read
Before you start
Is this guide for you?
- Best entry point
- Power Automate
- Time investment
- 6 min read
Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/power-automate-instant-low-code-plugins-to-run-powerfx-code/. Author: Matthew Devaney.
Power Automate: Instant Low-Code Plugins To Run PowerFx Code Posted by - Matthew Devaney on - October 27, 2024 16 Comments
Power Automate can run PowerFx code by calling an instant low-code plugin. An instant low-code plugin can take inputs from Power Automate, perform operations using PowerFx and then return the result to Power Automate. This is exciting because you can use the PowerFx language you know and love from elsewhere in Power Platform while not having to remember any Power Automate functions .
And as a bonus you can also call an instant low-code plugin from Power Apps to execute complex logic server-side instead of on-device. Table of Contents
Introduction: The Net Work Days Instant Plug-in Install The Dataverse Accelerator App Create An Instant Low-Code Plugin
“>Define Input And Output Parameters For A Low-Code Plugin
Write A PowerFx Expression For The Low-Code Plugin Save The Low-Code Plug-in To A Solution
Test The Low-Code Plug-In In The API Playground
Call The Instant Low-Code Plug-In From A Power Automate Flow
Run The Power Automate Flow And Get The Low-Code Plug-in Output
Introduction: The Net Work Days Instant Plug-in
An instant low-code plugin is used in a Power Automate flow to calculate net work days in similar manner to the Excel NETWORKDAYS function .
The low-code plug-in takes a start date and end date as inputs and outputs the net work days as an integer value. Install The Dataverse Accelerator App
Low-code plugins are built using the Dataverse Accelerator app which comes pre-installed with new environments. An older environment may not have it installed. To install the Dataverse Accelerator app go to the Power Platform Admin Center , then browse to Resources > Dynamics 365 Apps. The Install the app named Dataverse Accelerator.
Select an environment and press the Install button.
After the Dataverse Accelerator is installed a new application called Dataverse Accelerator App appears in the environment. Create An Instant Low-Code Plugin
There are two types of low-code plug-ins: Instant and Automated . An instant plug-in is triggered manually by performing an unbound action in Power Automate or Power Apps. An automated plug-in is triggered when a record in the specified table is created, updated or deleted.
We want to make an instant plug-in. Open the Dataverse Accelerator app and create an instant plug-in.
Define Input And Output Parameters For A Low-Code Plugin
A low-code plugin can include input parameters and output parameter. To calculate the net work days we will need both.
Name the instant plug-in “Net Work Days”. Then add two string type parameters Start Date and End Date.
We will use a string data type because Power Automate does not have a data type for dates.
Then create an outputs parameter with an integer data type named Days . The plugin will take a start date and end date as inputs and output the net work days as a whole number.
Write A PowerFx Expression For The Low-Code Plugin
Plugins use PowerFx code to perform operations and return a result. In a prior article, I showed how to calculate the business days excluding weekends in Power Apps. We can re-use the same code from that app inside the low-code plugin.
Copy and paste this code into the Expression field of the instant low-code plugin. To output the net work days we include a record with the parameter with Days as a field. { Days : With( {
// generate a one-column table of all dates between start date & end date
varStartDate : DateTimeValue(StartDate),
varEndDate : DateTimeValue(EndDate) }, If( And( IsBlank(varStartDate), IsBlank(varEndDate) ),
// show nothing if any date pickers are blank 0 , // include only dates Monday to Friday CountIf(
// generate a one-column table of all dates between start date & end date
ForAll( Sequence(varEndDate - varStartDate + 1 ), varStartDate + Value - 1
), Weekday(Value) in [ 2 , 3 , 4 , 5 , 6 ] ) ) ) } Code language: JavaScript ( javascript ) Save The Low-Code Plug-in To A Solution
Once the low-code plugin setup is completed we want to save it to a solution. Choose a solution from the dropdown and give the plugin a description. Select the global scope because the low-code plugin is not associated with any specific table. Save the low-code plugin.
A success notification appears at the top of the page.
And the plugin is added to the solution along with its other component parts.
Test The Low-Code Plug-In In The API Playground
A low-code plug-in can be tested before using it in Power Automate or Power Apps. Go to the API Playground by pressing the Update icon and clicking the Test in API Playground button that appears in the success notification.
Dates in Power Automate are expressed as a text string. For example, the date November 1, 2024 could be shown as “2024-11-01” or “2024-11-01T00:00:00Z”.
Choose the Net Work Days instant plug-in, fill in the query parameters with these values and then press send: StartDate: 2024-11-01 EndDate: 2024-11-30
The instant low-code plugin outputs a responses with Days equal to 21.
The work days for November 2024 are shown on this calendar. There are 21 work days.
Call The Instant Low-Code Plug-In From A Power Automate Flow
The low-code plugin is completed. Now we want to call it from a Power Automate flow. Create a new instant flow named Net Work Days Calculation .
Include two date type parameters in the flow trigger: Start Date and End Date .
Instant low-code plugins can be called as unbound actions in Dataverse. Add a Dataverse – Perform an unbound action to the Power Automate flow.
Select the action named NetWorkDays . Supply the Start Date and End Date from the flow trigger as parameters.
Run The Power Automate Flow And Get The Low-Code Plug-in Output
We’re done. It’s time to test our instant low-code in the Power Automate flow. Run the flow and choose a Start Date of 2024-11-01 and an End Date of 2024-11-30. The flow run completes successfully.
And “Days”: 21 can be found in the perform an unbound action outputs. Did You Enjoy This Article? 😺
Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?
If you have any questions or feedback about Power Automate: Instant Low-Code Plugins To Run PowerFx Code please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney Power Automate
Save Docusign Document To SharePoint With Power Automate
Tagged
Power Automate
Have a Microsoft 365 topic idea?
Share article suggestions, community session ideas, corrections, or real-world scenarios for future nxtM365 learning notes.
Keep learning Microsoft 365
Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.
Continue learning
Related tutorials
Related questions
Related comparisons
Next action