PowerFx - can it be used to evaluate Power Automate expressions in PAMU?
Aug 04, 2024 • Thyge S. Steffensen
Tags: PAMU, PowerFx
PowerFx
Power Fx is the low-code language that will be used across Microsoft Power Platform. It’s a general-purpose, strong-typed, declarative, and functional programming language. learn.microsoft.com
Power Automate Mock Up (PAMU) is a test runne for Power Automate flows, a cruciel part of the is to be able to evaluate expressions.
The first version was a reverse-engineered parser and evaluater of the expression language implemented in C# using Sprache.NET, which eventually made it on its own in ExpressionEngine. But, its foundation was ValueContainer, a wrapper for all values which grew in complexity and was confusing for users. I wanted to re-do it, maybe building on CLR types instead - but it would take time.
Then, Power Automate being on the Power Platform and Microsoft creating, releasing and open-sourcing PowerFx - maybe this was the future for Power Automate and maybe PAMU? So instead of re-implementing the expression language once again, I wanted to try to use PowerFx AND most importantly, get rid of ValueContainer.
PowerFx has its own “concept” of values, still not as ideal, but I’ll give it a try.
Discrepencies
PowerFx functions are starting with a capital letter, where Power Automate expressions are all lower case, and unfortnutaly PowerFx is case-sensitive and abs(-2) is the invalid version of Abs(-2).
ExpressionEngine has support for aliased functions, which would make it easy to just add an alias for all functions in Power Automate to the eqvivalent in PowerFx and viola - done. But no, the function name is given to the constructor.
Solution
So how do I utilize PowerFx to evaluate Power Automate Expressions and use it in PAMU?
I could:
- Write a transpiler, converting all functions to PowerFx eqvivalent
- Register all BuiltIn functions with the Power Autoamte eqvivalent name?
Besides that, I still need to somehow persist state so I can create the outputs and similiar functions from Power Automate.
Discoveries
Digging through the codebase looking for how to use it, I could not find the add function from Power Automate, because addition in PowerFx is 1 + 1 instead of add(1, 1), which makes it harder to “just” translate Power Automate expressions to PowerFx…
Furthermore, PowerFx is not piggy packing on .NETs support for dependency injection to manage and register functions and each function seems to be a singleton. So for me to support state, I need to build the PowerFx function backlog for each “scope”, instead of getting a Scoped Service Provider… or to implement scope in the state provider.
Furthermore, Power Automate expression can retrive object properties using [ ], so .bool would be eqvivalent to ['bool'] in Power Automate expression, but that’s not the case in PowerFx. Make it even more difficult to utilize PowerFx as the expression evaluator in PAMU.
Please create an issue if you have a comment - and then I'll know I have to prioritize comment functionality