cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Nusserdt
Advocate I
Advocate I

PowerApps don't wait for Select() outcome

To recycle my code and reduce the complexity, I start to put code snippets in to buttons and call them like functions with Select().

But I recognize that the compiler/engine do not wait for the outcome of the Select() function. Therefore I construct a simple reproducible example with two variables _test and _rand:

Nusserdt_1-1603002838214.png

User Button:

 

Select(TestFunction);;
Set(_test; Text(_rand))

 

User Reset:

 

Set(_rand; 0);;
Set(_test; "");;

 

TestFunction:

 

Set(_rand; Rand())

 

Label _test:

 

"_test: " & _test

 

Label _rand:

 

"_rand: " & _rand

 

 ---

User Button calls TestFunction and overwrite _test with variable _rand, setted inside TestFunction. My expected outcome would be:

 

_test == _rand

 

but it's not. _test only get the value of _rand in the next cycle.

How can I get this example to run?
(possible solutions could be a Timer, but I hope for a easier approach)

1 ACCEPTED SOLUTION

Accepted Solutions

Thanks for your reply Eelman. I play a bit more with my test scenario and I could easily solve the puzzle with putting everything after the Select() call from the User Button into a TransferFunction:

Nusserdt_0-1603018208646.png

Changes I made

User Button:

 

Select(TestFunction);;
Select(TransferFunction)

 

 TransferFunction:

 

Set(_test; Text(_rand))

 

In result you will have a lot of buttons, but in my mind it is still better that 500 lines of code inside a 860x640 popup window. At least you could make a function screen for the buttons. Programming in 2020 get real.

View solution in original post

2 REPLIES 2
Eelman
Community Champion
Community Champion

@Nusserdt 

Yep, you are correct, PowerApps looks at Select() as one line of code then runs the code following it straight away - not mater how long the code inside the Select() needs to run for. I ran into this issue awhile ago.

 

My only solution was to add the code that needs to wait for the Select() to finish inside my Select(). You could use a Timer but you would just be guessing the length needed or adding extra User lag time to your app depending on the code complexity.

 

Unfortunately, PowerApps isn't built to handle functions.

Thanks for your reply Eelman. I play a bit more with my test scenario and I could easily solve the puzzle with putting everything after the Select() call from the User Button into a TransferFunction:

Nusserdt_0-1603018208646.png

Changes I made

User Button:

 

Select(TestFunction);;
Select(TransferFunction)

 

 TransferFunction:

 

Set(_test; Text(_rand))

 

In result you will have a lot of buttons, but in my mind it is still better that 500 lines of code inside a 860x640 popup window. At least you could make a function screen for the buttons. Programming in 2020 get real.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,686)