Microsoft Office 365

Only 1 Input property needed for all Power Apps components

Do you end up with many input properties when you develop Power Apps components? You only need 1 input property!

Power Apps components

Earlier today I mentioned Power Apps components in my post about call a flow from Power apps components. That post made me think about passing parameters into Power Apps components. When you end up with many parameters it becomes a bit of a pain to deal with

Record type Input property

I’m going to use a similar method as I’ve done with Power automate in the past, where I reduced the number of parameters sent to a flow.

In this case i’m going to use the same component as mentioned in my earlier post. I’m just going to add a new property calls IN. This property will be of the type Record.

This IN parameter is going to hold all the details that my component needs.

Now there is one important things to note! Tick that box! Raise OnReset when value changes.

To make sure that the component gets a change made to your input property, you will need to tick this box. If you don’t, well it will work once.

JSON

Inside my component I’m setting the IN parameter to the following bit of json. The ButtonName is going to be used by the label button to display a text and the Colour is used to set the background (Fill) of my component.

{ButtonName: "Red", Colour: Red}

I’m going to leave the original fields there but there is no real need for them anymore.

The component instances in the app

Now i created my traffic light in my Power App again and all i need to do is set the IN property for each of the instances of my component to the following code.

{ButtonName: "Green", Colour: Green}

And I use a similar code for the amber component. If you want to you can of course also use the RGBA function inside the above json code to get more control over the colours that you want.

So now I’m setting 2 things in one property.

Creating new properties?

Creating new properties is as simple as just editing the json. Just add some new test properties within your component and then update the component instances in your app to use the same format.

Arrays in the parameter

So far I’ve looked at simple code with text and colours and in a similar way you can also use numbers. But how about arrays of data?

It is all equally simple.

The example below includes an array of data as well.

{ButtonName: "Green", Colour: Green, MyArray: [1,2,3,4,5]}

It is even possible to use something like items inside an array that are more complicated.

{
    ButtonName: "Green",
    Colour: Green,
    MyArray: [
        {number: 1},
        {number: 2},
        {number: 3},
        {number: 4},
        {number: 5}
    ]
}

Output properties

In a similar way as the input property, you can also create a single output property. So that the component can pass data back to the app.

After I have created my OUT property I will set the OUT property to Self .IN

For more about Self please read my post about Parent, Self and ThisItem

And from within the app I can now get to all my data in the output parameter using the following expressions.

First(MyComponent_2.OUT.MyArray.Value).Value.number

Tables

In all the examples here i used the Record data type as a base. For any of this I could also have considered using the table data type instead as that will give me an array of data at the root level of my json code.

So if I wanted to get or return multiple items then that might be a good options. However in most cases a single record will be good enough.

Share
Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

Recent Posts

Introducing 8 AI Functions for Dataverse in Power Apps

Recently Microsoft added AI Functions to Dataverse that can be used in Power Apps. In…

8 hours ago

Copy and paste Scope steps in the new Power Automate Designer

One of the outstanding issues with the new Power Automate Designer is Copy and Paste…

1 week ago

Receive the available storage within your SharePoint Online tenant

Within the SharePoint admin centre there is that little detailed overview, telling you the available…

4 weeks ago

Options for Documenting Your Power Apps: Comments, Code, and Controls

Within Power Apps there are various ways to document your app. In this post I'm…

1 month ago

2 ways to duplicate SharePoint Lists to support your Power Apps

Recently I've been asked quite a few times to duplicate SharePoint lists as part of…

1 month ago

Update a Hyperlink Column in SharePoint with Power Automate

Today, I was asked about how to create a lookup to a document or item…

1 month ago