PCF: getOutputs

The getOutputs method of the PCF components seems pretty self-explaining: (https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/control/getoutputs)

It is called by the framework prior to a component receiving the new data. Returns an object based on nomenclature defined in manifest, expecting objects[s] for the property marked as bound or output.

I was a little unsure about the possibility of PCF components to set the values back to null. It seems to me a little inconsistent because we get passed

  • “string | null” as a raw input value in the context.parameters,
  • but the value should be returned as “string | undefined” in getOutputs().

To set the value to null, return undefined

As I hoped, returning undefined in getOutputs, sets the value to null, and triggers all the events:

  • goes through updateView method (both own PCF and another PCFs registered on same attribute)
  • triggers the events attached on the form with addOnChange

Omitting properties doesn’t mean that they are undefined

Here is where it gets interesting. If we omit some properties in getOutputs results, the value is not set to null: they will be skipped. It won’t trigger any events, and no updateView will be called for the omitted properties. It will reflect the changes only for the provided properties.

For instance, in the previous example, we comment the first properties.

This will update only the booleanProperty but the value of the targetProperty and validProperty won’t be touched.

This could be useful if the PCF needs to report some changes while some other properties are not valid, so they shouldn’t be reported to the Framework Runtime. Another use-case that I’ve saw was, when a set of PCFs interact with the same attributes; sometimes they need to pass values between each-other, but sometimes it’s important to be able not to set the values (maybe even avoid loops).

This is the behavior right now. Since the documentation doesn’t describe this, so it’s not unsupported but I cannot be sure that it will stay this way. I should also mention that I only made the tests in a ModelDriven App. I have no idea what happens in a CanvasApp.

4 thoughts on “PCF: getOutputs

Add yours

  1. Wanted to let you know that if you return any variables as undefined in the getOutputs for Canvas apps the OnChange event will not fire for the Code Component. This will cause the output parameters to not update and you won’t be able to respond to events in the OnChange event of the control.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑