Search code examples
powerappspowerapps-canvas

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 Collect() code executes AFTER the UpdateContext() code executes?


Solution

  • I'm sorry, but it is correctly working, sequentially. After the showDialogBox context gets updated to true, the collect will happen. If the collect should happen after the actions of your DialogBox, you should fire the collect from within your showDialogBox.