cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver II
Resolver II

Code after Select(SomeLabel) not executed

To make my code a bit more manageable I put a part of the onvisible code of a form in the onselect of a label.

In my onvisible code I would do something like

(UpdateContext({lTest:"1"}) 
;;(UpdateContext({Someboolvar:false}) 

;;If(
  Someboolvar
  ; somecode
  ; select(somelable)
    ;;(UpdateContext({lTest:"3"}) 
)

(in Holland , = ;  and ; is ;;)

In the onselect code for somelable:
(UpdateContext({lTest:"2"}) 

If I run the code using a label monitoring lTest, lTest gets stuck at 2. So the code in somelable is executed, but the code that sets lTest to 3 not. Is this expected behaviour?

4 REPLIES 4
Highlighted
Power Apps
Power Apps

Re: Code after Select(SomeLabel) not executed

The code after Select(SomeLabel) is actually executed, but its effect is being overwritten by the action in the label's OnSelect. I was able to reproduce this issue in an app with a button and a label (you can see it in the attached app). The button's OnSelect:

Clear(actions)
;; Collect(actions; {Timestamp:Now(); Text: "[Button.OnSelect] UpdateContext (1) in button"});; UpdateContext({lTest:"1"})
;; Collect(actions; {Timestamp:Now(); Text: "[Button.OnSelect] Calling Select(Label)"});; Select(Label1)
;; Collect(actions; {Timestamp:Now(); Text: "[Button.OnSelect] UpdateContext (2) in button"});; UpdateContext({lTest:"3"})

And the label's OnSelect:

Collect(actions; {Timestamp:Now(); Text: "[Label.OnSelect] UpdateContext in label"});; UpdateContext({lTest:"2"})

 When we click the button, we see that the actions are executed in the following order (based on the actions collection):

  1. UpdateContext (1) in button
  2. Calling Select(Label)
  3. UpdateContext (2) in button
  4. UpdateContext in label

I'm not sure whether this is expected or not - one could see the Select function acting as adding the OnSelect expression for the selected control to a queue that is executed after the current expression - but it does look strange. I've open a bug to the team that owns this expression to see what they have to say about this.

Hope this helps.

Highlighted
Super User
Super User

Re: Code after Select(SomeLabel) not executed

@HansHeintz 

It appears your code has a few syntax errors which could be preventing it from executing

(UpdateContext({lTest:"1"}) 
;;(UpdateContext({Someboolvar:false}) 

;;If(
  Someboolvar
  ; somecode
  ; Select(somelable)
    ;;(UpdateContext({lTest:"3"}) 
)

 

I rewrote your code and tested to ensure there was no issues with using it.

 

UpdateContext({lTest:"1"});;
UpdateContext({Someboolvar:false});;
If(
  Someboolvar;
  some_code;
  Select(some_label);;
  UpdateContext({lTest:"3"}) 
)

 

Please note there are 2 other reasons why this code might be not working for you

 

#1 Your NAVIGATE function used to get to the screen did not supply any Context variables

 

Navigate(Screen1,None,{lTest:"0", Someboolvar:true})

 

#2 Some code executed during the SELECT(some_label) overwrites the context variables.

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Community Support
Community Support

Re: Code after Select(SomeLabel) not executed

Hi @HansHeintz ,

Based on the issue that you mentioned, I have made a test on my side, and the issue is confirmed on my side. Actually, the code after the Select function is executed successfully, but the UpdateContext({lTest:"3"}) formula execution speed in OnVisible property of a screen is faster than the UpdateContext({lTest:"2"}) formula in your somelabel, so the ITest context variable would be overrited with "2" always. (UpdateContext({lTest:"3"}) formula is executed before the UpdateContext({lTest:"2"}) formula)

 

As an alternative solution, please consider modify your formula as below:

 

UpdateContext({lTest: "1"});;
UpdateContext({Someboolvar: false});;
If(
   Someboolvar;
   somecode;
   Select(somelable)  // Modify formula here
)

 

set the OnSelect property of the somelabel to following:

 

If(
   Someboolvar;
   UpdateContext({lTest:"2"});
   UpdateContext({lTest:"3"})
)

 

Please consider take a try with above alternative solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Resolver II
Resolver II

Re: Code after Select(SomeLabel) not executed

If I understand correctly, putting code in a button is a bit like starting a concurrent stack without a formal statement, which could be called an upside. Downside is that having a piece of code stored in some button label to be executed and return from when you need it, like a procedure in a conventional programing language, is actually not at all possible in powerapps. 
Since it is te latter I want to achieve, for purposes of reusability and of clarity, I don't think my problem is solved.
Is it a directive of powerapps development to not have functions or procedures (like it should not be too professional because it would cost market share of some other tools) or might they ever be introduced?

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,446)