cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TechnoKitty
Helper I
Helper I

PCF - On... handler property

Hi there!

I'm building a component that processes some data and should fire "OnSuccess" and "OnError" events as an outcome. This can be used then in a Power App to present the results accordingly. Think like "OnSelect" standard button property or "OnTimerEnd" etc. 

So, I'm looking for a way how to define such a property and cannot find this in the documentation. How might I accomplish that?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @TechnoKitty ,

I totally agree with @ben-thompson  and @DianaBirkelbach .

In PCF, it's not supported to create custom behavior properties like "OnSuccess" and "OnError" currently.

For now, you could just  register the OnChange event.

But you could use output property and set it to some value when the event happens, which should work as "OnSuccess" and "OnError".

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
v-yutliu-msft
Community Support
Community Support

Hi @TechnoKitty ,

Do you want to use behavior properties like "onselect" in component?

I'm afraid there's only one behavior property "OnReset" supported in component.

You could follow this doc to know how to use this behavior property in many ways:
https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/component-behavior

What's more, you could also consider use a Toggle's OnChange to achieve the feathers that you want.

Here's a similar issue for your reference:

https://powerusers.microsoft.com/t5/Building-Power-Apps/Navigation-from-Dialog-Components/td-p/49321...

 

I'm very glad to find that this feather has been started to developed, hoping to see it soon!

https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Actions-on-Components/idi-p/238399

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you, @v-yutliu-msft - I voted for the idea!

Just want to clarify, my question was about code components, not the "custom component" that is created in Power App Studio. Does it change your answer anyhow?

In PCF you cannot define custom events.

I'm not a pro in CanvasApps, but since for PCFs you can only register the OnChange event, maybe you can work with special values in your PCF, that you evaluate in CanvasApp to decide if you treat it as a "OnSelect" or "OnTimerEnd" event.

So you set the PCF property value to the string "OnSelect" or to the string "OnTimerEnd", and the CanvasApp register to OnChange event of your PCF and decide which event was actually meant. 

PCF Controls of type boolean might work too(so you only check if it's true=OnSelect, false=OnTimerEnd)...

But this is only an idea,  I've never tried out if this works...

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
ben-thompson
Solution Sage
Solution Sage

I'm confused by why you are using a PCF component to manipulate data - as unless user interaction is required that really should be a server level task .

 

A PCF component is really a user interface component, you pass parameters into it and the control then renders the information in the way you want it to work.  PCF components are also built on a framework with defined interfaces / events that are the only things the canvas / CDS form expects to interact with so you cannot add your own events as they would be ignored (webresources are still supported for exactly that reason).

 

That doesn't mean that you can't do most of what you want. 

 

For onSuccess calling notifyOutputChanged within your code will tell the form that the data is valid and will trigger the form calling getOutputs to receive the newly updated values of the parameters the control is bound to (note, I believe canvas components work slightly differently).

 

Error handling and errors however need to handled within the control itself. 

 

Finally don't forget you can bind an attribute to multiple controls - we do this on all our admin pages that used to need 100s of lines of Javascript but now consist of zero code and multiple PCF components - where one control (selectEntity) acts as the master control / trigger for various select attribute / select view / select lookup controls underneath. 

 

 

 

 

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".

@ben-thompson 

This is a Canvas app component. It does some front end logic and manipulate data using fetch() request to an external server. When it's done, the other app logic needs to happen - e.g. Navigate to the next screen.

Your and @DianaBirkelbach thoughts helped me to understand that I can use output property and set it to some value (e.g. "Processed") when the event happens. This would solve the problem in a way that other components can read it (e.g. I can define a button with property Enabled set to MyComponent.Result = "Processed"), but it doesn't help to do an action automatically (e.g. Navigate).

So, missing really the "On..." events in the frameworks (for Canvas app components) 

Hi @TechnoKitty ,

I totally agree with @ben-thompson  and @DianaBirkelbach .

In PCF, it's not supported to create custom behavior properties like "OnSuccess" and "OnError" currently.

For now, you could just  register the OnChange event.

But you could use output property and set it to some value when the event happens, which should work as "OnSuccess" and "OnError".

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

This worked perfectly, thanks again!

Thanks @v-yutliu-msft, that's great to hear the the OnSelect event would be added to the PCF component, but can we assume you will also add the support for the Select on the PCF component at the same time?

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (3,143)