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 / Custom Components: Upd...
Power Apps
Unanswered

Custom Components: UpdateContext (local variables) not working

(0) ShareShare
ReportReport
Posted on by 353

I'm trying to use custom components to create functions (reusable code). However, I've notice it seems to be impossible to use global variables (which is understandable because it is bad programming practice and makes the code less re-usable), BUT it also seems impossible to use UpdateContext to declare local variables either. This sort'a puts a damper on the whole custom function hack. Is the any way to declare variables on a custom component? Here's the tutorial I was following and adjusting to meet my needs....

 

https://matthewdevaney.com/power-apps-custom-functions-reusable-code/#:~:text=Build%20A%20Function%20Component,-Let's%20get%20started&text=Open%20Power%20Apps%20Studio%20and,Data%20type%20Date%20and%20time.

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @carlilelance 

    You can ONLY use global variables in your components.  Context variables are not allowed.

    Global variables in a component are ONLY global to the component.

     

    I hope this is helpful for you.

  • carlilelance Profile Picture
    353 on at

    But I'm unable to use global variables that I create using...

    Set(...)  

    ...like as in...

    Set(var1, value1);

    Or am I doing something wrong? 

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @carlilelance 

    Not sure what you might be doing wrong as that works just fine in a component.

    What is the error you get?

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @carlilelance 

    Were you able to make any progress on this?

  • carlilelance Profile Picture
    353 on at

    Sorry, I got locked out of my account for some odd security reason. I'm not sure why, but now it's back. 

    The error I'm getting is "Name isn't valid. This identifier isn't recognized". See below. 

    carlilelance_0-1617905128138.png

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @carlilelance 

    That formula doesn't make any sense...what is it that you are trying to do there?

     

  • carlilelance Profile Picture
    353 on at

    I'm was just testing the fact that local variables don't seem to be working. I was using an actual formula in a solution and getting the same error. What would be a formula that would work? It is expecting an integer. 

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @carlilelance 

    Well what was not making sense is that you were doing a behavioral function along with an evaluated function in the same place. 

    Your Set function must be done on a behavioral action - you cannot put it into a property.

    I really need to understand more about what you are actually trying to accomplish to make any recommendations on a formula.

  • carlilelance Profile Picture
    353 on at

    My major end goal is to be able to make functions so I don't have to keep copying and pasting code dozens of times. That is what the tutorial was going for. 

     

    https://matthewdevaney.com/power-apps-custom-functions-reusable-code/

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @carlilelance 

    Yes, this is quite easily done now in components.  I am not familiar with the link you shared specifically, but what area are you having problems with?

    In general, to make a component a function component, you need to provide an Output property with a parameter.  In that property you would perform your function.

    Ex.  If you add an Output property to your component and call it Calc (numeric) and then have that property require a parameter (let's call it Base (numeric required)).  Then in the Calc property of the control you can do something like -  Base + 100 

    With the component in your app, you can reference the function with yourComponent.Calc(200)  this would return 300.

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 352 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 323

#3
Mohsin Ali Profile Picture

Mohsin Ali 226

Last 30 days Overall leaderboard