Hope all doing well. I just need to know if there is any way to pass data and trigger one PCF control from other PCF control. Let say, we have one PCF control containing dropdown List and other PCF showing details related to the selection in 1st PCF. When user select from dropdown in 1st PCF control ,it will run some business logic and show the results in 2nd PCF control.
I mean, if there is any way to achieve this?
@ScottDurow (superman) 🙂
Hi @MHammad , I don't know if this will answer your question completely, but your 2 PCF are bound to fields on the form they can communicate with each other natively.
In fact, they don't have to know each other at all the magic happens in how the properties are defined in the manifest of the PCF and to what field you bind your properties on the form.
PCF 1 = Color Picker, bound to a text field that will store the output of the color picker
PCF 2 = Sparline control, bound to the same field. (defines the color of the sparkline)
When the output of the Color Picker changes, the color of the sparkline is updated in real-time
For sure the same can be applied to your use case.
As @drivard points out if you bind two columns (note new terminology) to your PCF component as the parent column is updated (in the other control) the page will pass the change to your main PCF component while triggering the updateView event and you can then run your business logic on the newly updated value.
As an aside, If you business logic is time consuming (even if it's just a few lines of code) I find it useful to keep an internal version of the parent value and only run the business logic after confirming that the parent value has really changed - there are a lot of other reasons why updateView can be called - a value change is one of the rarer events.
Hi @MHammad ,
In case you need to catch a click an raise some kind of event for the first PCF, and only on this event the second PCF should get noticed, I'm not sure if you can filter the changing of attribute values the right way, because I'm afraid that the second control will be triggered also when the first updateView is called (you cannot know that the value is really changed, or is it because of control initialization).
Custom Events for PCFs in on the roadmap (no idea when), but until then maybe my blog about using postMessage to communicate between PCFs might help: https://dianabirkelbach.wordpress.com/2020/05/15/can-pcfs-communicate/.
Join us for the next call on August 17, 2022 at 8am PDT.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.