cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powaya
Helper I
Helper I

How do I make sure that my code executes sequentially in Power Apps?

I'm building a Power App that allows a user to take pictures using their smartphone camera and upload the image to a sharepoint list. To build the app I went to Insert > Media > Camera. The user simply user taps on the the live image in the app to take a picture. The tapping event triggers the OnSelect code for the Camera control, which is the following:

 

UpdateContext({showDialogBox: true});

   Collect(
      colImages,
      {
         DisplayName: ImageTextInput.Text & ".jpg",
         Id: ImageTextInput.Text & ".jpg",
         Value: Camera1.Photo
      }
   )

 

A dialogue box then opens with a field called ImageTextInput, then the user enters the desired name for the image. And here is where I have a problem: The Collect() code that you see above executes before UpdateContext() code, and therefore the image name ends up being blank. Why is that? How can I get UpdateContext() to execute first, so that it stores the user's desired name for the image BEFORE the Collect() code executes?

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User
Dual Super User

Its not that the Collect code executes first.  The UpdateContext() executes first, then the Collect, then the app reacts to the change in the showDialogBox variable. I would move the Collect() function to whatever you are using to close the dialog box.  That way the order will be preserved. 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

3 REPLIES 3
Pstork1
Dual Super User
Dual Super User

Its not that the Collect code executes first.  The UpdateContext() executes first, then the Collect, then the app reacts to the change in the showDialogBox variable. I would move the Collect() function to whatever you are using to close the dialog box.  That way the order will be preserved. 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
powaya
Helper I
Helper I

@Pstork1 Thank you! You're brilliant. You have no idea how much time I was spending on that problem

Pstork1
Dual Super User
Dual Super User

One of the keys to working with Power Apps that a lot of people have trouble understanding is that it is "Declarative" not "Procedural".  That's the root cause of what you are seeing.  You can't change properties of objects at runtime so you have to set a variable and let the object register the change.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,774)