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

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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

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