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.

Join me at 365 and Pwr EduCon in Chicago
EduCon Chicago 2022

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.

Join me at 365 and Pwr EduCon in Chicago
EduCon Chicago 2022

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.

Join me at 365 and Pwr EduCon in Chicago
EduCon Chicago 2022

Helpful resources

Announcements
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

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.

<
Users online (4,305)