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 / Setting Component inpu...
Power Apps
Unanswered

Setting Component input property default to a Global Variable?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I'd like to create a print button in my app to be used across multiple screens.  The printout itself is handled easily enough by writing to HTML and outputting via power automate.  The part I am looking for insight with is passing variables into a component. I have it working exactly as I need it to, but there are some errors being thrown and I'm not sure why exactly. Apologies in advance for the long winded post.  

 

First, I create a simple collection and record variable and use those within a Concatenate() and Concat() function to output a simple HTML table:

 

ClearCollect(
 ExampleCollection,
 Table(
 {
 item: "item1",
 value: "value1"
 },
 {
 item: "item2",
 value: "value2"
 },
 {
 item: "item3",
 value: "value3"
 }
 )
)
Set(ExampleVariable, {Title:"Table Title", Col1:"Item", Col2:"Value"})
Set(HTML,Concatenate(
"<html>
<head>
</head>
<body>
<table>
<thead>
 <tr><th colspan=2>"&ExampleVariable.Title&"</th></tr>
 <tr>
 <th>"&ExampleVariable.Col1&"</th><th>"&ExampleVariable.Col2&"</th>
 </tr>
</thead>
<tbody>",Concat(ExampleCollection,"<tr>
 <td>"&item&"</td>
 <td>"&value&"</td>
 </tr>"),"</tbody>

</table>

</body>
</html>"))

 

 

 

This works just as expected:

 initialoutput.PNG

 

The issue with this is that my html is much more complex than the above and must be used across many screens, so I'd like to use a custom component to store and update the code in a single location.  So, I create a component with a single button and the same OnSelect formula as the print button, which of course throws an error due to the variable:
ComponentVariableError.PNG

 

If I add an input property (VariableIn as a Record) and an output property (VariableOut as a string), I can then add the component to a screen, set the VariableIn property to my ExampleVariable from earlier, and everything works again:

VariableIn.PNGVariableOut.PNGComponentVariableFixed.PNGWorkingComponent.PNG

(I promise I'm getting to the point...)

 

The problem with THIS is that if I ever want to change the structure of my VariableIn property (for example, if I want to add a Col3 field), then it resets all of the inputs to default on each screen that I previously added the component to, which is a real pain (as I mentioned, there are a lot of input properties and a lot of screens): 

FieldAdded.PNGresettodefault.PNG

 

SO, I wonder if I can simply set the default value within the component to my ExampleVariable so that I can simply change or add fields without ever touching the default value within the component.  This throws an error:

VariableError.PNG

 

BUT, it actually works perfectly!  And, even with the error, intellisense recognizes the record fields from within the Component:

intellisense.png

There are no errors within the actual button formula, only on the input property of the component itself. Beyond that, it works exactly as I need it to and I can add it to as many screens as I want without ever having to manually set the input.  If I want to add a field to my ExampleVariable, I do have to clear out the component input default and paste it back in before it's recognized within the button formula, but that's literally just a single cut and paste and a whole lot easier than going through and resetting the input properties on every single screen of my app.  

 

Finally, on to my actual questions...  

 

1 - Is there a better way to acheive this result without any error messages?

2 - Beyond the fact that an error is shown, is there a risk or downside to doing this? Thus far, I haven't been able to find any undesired behavior, and that's with about 20 input properties of various types in my actual print component.

 

Categories:

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 382 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 329

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard