web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Ability to add public ...
Power Apps
Unanswered

Ability to add public methods or events to a PCF control

(0) ShareShare
ReportReport
Posted on by 48

I am trying to build a PCF control that replaces the OOB Multi-select optionset control.  One of the things that I can't figure out is how to add public methods to my control such that a form script is able to interact with my PCF control.  For example, I need to be able to add the following methods (that the OOB control has):

addOption(1234)
removeOption(1234)
clearOptions()
getOptions()

It seems like it should be possible based on the response to a similar question here: https://powerusers.microsoft.com/t5/Power-Apps-Pro-Dev-ISV/Form-designer-setting-additional-methods-and-scripting-of-PCF/m-p/312074 

 

However, I've created similar methods on my class that implements the `ComponentFramework.StandardControl` but it doesn't appear to work.  Is this possible?  If so, where should I be placing my methods?

I have the same question (0)
  • skoofy5 Profile Picture
    482 on at

    I just a did test with a dropdown control we have on top of an custom option set control and the 'removeOption' method seems to work. Is it triggering the updateView of your control and is your control being re-rendered?

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/removeoption

  • Steven Rasmussen Profile Picture
    48 on at

    @skoofy5 - Thanks for the reply!  When I try the following in a form "onLoad" script with my custom PCF I get an error: "TypeError: control.removeOption is not a function"

    let control = this._formContext.getControl("mrs_legs"); // My custom PCF control
    control.removeOption(123); // Throws the exception: TypeError: control.removeOption is not a function

     

    If I change the control back to the default then I don't receive that error.

     

    My control is very basic at this point but here it is:

    import * as React from "react";
    import * as ReactDOM from 'react-dom';
    import AdvancedMultiSelectControl, { IAdvancedMultiSelectProps } from "./AdvancedMultiSelectControl";
    import { IInputs, IOutputs } from "./generated/ManifestTypes";
    
    interface IAdvancedMultiSelectState extends ComponentFramework.Dictionary {
    
    }
    
    export class AdvancedMultiSelect implements ComponentFramework.StandardControl<IInputs, IOutputs> {
     _container: HTMLDivElement;
     _initialVisible: boolean;
     _initialDisabled: boolean;
     _optionSetMetadata: ComponentFramework.PropertyHelper.FieldPropertyMetadata.OptionSetMetadata;
    
     constructor() {
    
     }
    
     public init(
     context: ComponentFramework.Context<IInputs>,
     notifyOutputChanged: () => void,
     state: IAdvancedMultiSelectState,
     container: HTMLDivElement): void {
    
     this._container = container;
     this._initialVisible = context.mode.isVisible;
     this._initialDisabled = context.mode.isControlDisabled;
     this._optionSetMetadata = context.parameters.controlProps.attributes!;
     }
    
     public updateView(context: ComponentFramework.Context<IInputs>): void {
     ReactDOM.render(React.createElement(AdvancedMultiSelectControl,
     {
     values: [],
     } as IAdvancedMultiSelectProps),
     this._container);
     }
    
    
     public getOutputs(): IOutputs {
     return {};
     }
    
     public destroy = (): void => {}
    
     public clearOptions = () => {
     alert("Clear options");
     }
    
     public getOptions = () => {
     alert("Get options called");
     }
    
     public removeOption = (option: number) => {
     alert("Remove option");
     }
    
     public addOption = (option: number) => {
     alert("addOption");
     }
    }

     

    Are you able to share the code from your control?  I must just be not understanding something correctly.  Thanks!

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Just to get a little more precise @srasmussen .

    I don't think that the PCFs have the possibility to define own methods.

    On the roadmap is only the definition of custom events, similar to Canvas Components. That was announced for Wave 2, 2021 and hopefuly will be soon available: https://docs.microsoft.com/en-us/power-platform-release-plan/2021wave2/power-apps/code-component-improvements?WT.mc_id=BA-MVP-5004107#:~:text=Code%20components%20will%20have%20support%20for%20events%20in%20line%20with%20the%20canvas%20apps%20native%20components.%20This%20will%20enable%20developers%20to%20define%20custom%20events%20that%20can%20be%20raised%20by%20code%20components.

     

    The same as @skoofy5 checked, I could verify too that my ColorfulOptionset PCF does have the standard methods (like .getOptions()), exactly like the other standard methods like .setDisabled() and so on. But these are not methods defined inside the PCF, but methods defined for the base type of your PCF. 

    These standard methods can be called from form scripting, and the result are the disabled state, or the options provided through the parameters,
    For instance .removeOption(...) will call the updateView of your PCF , where context.parameters.optionsInput.attributes.Options doesn't have that option anymore.

    Hope this helps!

     

  • skoofy5 Profile Picture
    482 on at

    Interestingly from that same article, @DianaBirkelbach 


    "For model-driven apps, code components can be created for the simple lookup and Multi-select option set (Choices) type, and properties of these new types can also be added. These are top community requests. Additional framework APIs on the canvas apps will be added, which approaches model-driven app parity."

     

    Does that mean support for multiselect isn't ready yet?

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Hi @skoofy5 
    I think it depends how you read the statement. I understand it just as "we can define these properties and use them".
    It is confusing, indeed. Maybe I'm wrong.

    In my opinion the lookup and multioptionsets are avaibale only for model-driven apps for now.

    Even in model-driven apps, considering lookups there are still a lot of properties we need to get from the platform (like in this blog where all these properties for lookup are unsupported: https://dianabirkelbach.wordpress.com/2021/06/19/lookup-pcf-lets-dive-deeper/). Right now we have only the way to get or chnage the value for the lookup; I suppose there is still a lot to come. So no, it's not ready.

     

    But I don't understand the statement above talking about custom methods for PCFs. As I said, could be just my opinion.

     

     

     

  • Steven Rasmussen Profile Picture
    48 on at

    @DianaBirkelbach - That makes sense about the custom functions. Unfortunately, I'm still not able to take advantage of the OOB methods for a MuliSelectOptionSet (ie "addOption" etc).  Perhaps my manifest isn't setup properly or something?  I'm fairly new to PCF controls so that very well could be the issue. I've pushed my project to a Github repo here: https://github.com/StevenRasmussen/PCF.AdvancedMultiChoice 

     

    If you have any further thoughts or can point to a repo with a working example it would be much appreciated.

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    The manifest is looking good, @srasmussen .

    If the manifest would be the problem, you wouldn't be able to load the component on the form.

    Maybe is really a bug with the MultiOptionSet ? I don't have one to try it out right now.
    But you could try to register the sdk example for MultiOptionSet PCF: https://docs.microsoft.com/en-us/powerapps/developer/component-framework/sample-controls/multi-select-option-set-control?WT.mc_id=BA-MVP-5004107 and check there if the methods are available.

  • Steven Rasmussen Profile Picture
    48 on at

    @DianaBirkelbach - Thanks!  For some reason I missed that documentation.  I'll give it a try and post results here.

  • Steven Rasmussen Profile Picture
    48 on at

    @DianaBirkelbach - Just deployed and tested the example PCF control and it unfortunately has the same problem 😞  So it appears that this is a genuine bug with the MultiSelectOptionSet control.  Do you have any ideas on how to report this to MS?  Do they monitor these forums at all?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 846

#2
Valantis Profile Picture

Valantis 532

#3
Haque Profile Picture

Haque 410

Last 30 days Overall leaderboard