Power Fx with PCF

 


Today, I was checking up on PCF Controls to see if anything new has shown up, as I have stepped away from PCF development for a few months. I saw this new (at least new to me) 'Event' property.


I can do what?! Pass PowerFx formulas to be called inside PCFs?! I dug some more into it.


So it seemed that the context would have an event object, with event(s) as properties of that event object. (I assumed this would be generated the same as properties were). I followed the Microsoft documentation and created an event in my manifest file. It failed on build with an error saying "Error Definitions are not supported."


Assuming this was a very new feature, I decided to dig into pcf files in the node modules. I found a file called featureFlags.json and found a property called "pcfAllowEvents" and set it to "on". Setting this to on let my project build. I then tried to access the 'events' on the context object, however, it still has not been added yet (probably why pcfAllowEvents is turned off 😀 ). So I had to write a function to cast the context to type of any and work from there.

I then created a canvas app, and created a context variable called powerfxPCFValue and set it to 0 on visible of the page. 
I added the component to the canvas app and it has a PowerFxFunction property, which is the name of the event in my ControlManifest. I added a PowerFx function to increment the powerfxPCFValue by 1.

I then created a label to just show the value changed.

I clicked the button of the PCF, and it worked!



I then tried creating an Account record using a patch statement and it worked.


However, updating an Account record using a patch statement does not.



It seems that this feature is still very new (as one shouldn't have to update a json file in the node modules to use it), so it will be awhile before I will be using this in production. However, this will allow a nice cohesion between PCFs and Canvas Apps. The biggest win here is passing in Patch statements to create/update/delete records, as canvas apps can't call the PCF WebApi. Another use case would be you need to set a context variable to a value once the PCF has done some sort of action. The PCF could perform it's action, then call the formula after. 

As you can see in the examples with the patch, it allows for multiple PowerFx functions to be passed in, delimited by a semicolon. This will be very useful to make multiple PowerFx function calls in one go.

 Excited to see how this feature is used by the community!









Comments

Popular posts from this blog

Spinner for Canvas App or Custom Page in PowerApps using Fluent UI

Search ALL formulas, controls, screens and more within a Canvas Apps & Custom Page!!