Does anyone know how threading works in Canvas Apps functions when it comes to behavior functions? I have a confirm button with an OnSelect that Selects Button "A" and Button "B". Button A's OnSelect Performs a call to an Azure DB, and then sets a context variable with a result. Button "B" checks for this variable and determines what screen to navigate to next. With this setup, Button "B"'s function is executing before Button "A" sets the context variable. My work around is to select Button "B" from "A".
Given that Select() calls get put on a queue according to the documentation and that the functions are ran in JS by the end of the day, my hypothesis is that anytime a function performs a call to get external data, it's done async via a promise, then allowing other functions to run, resulting in Button "B" getting executed before Button "A" actually sets the context variable. Can anyone confirm or deny this hypothesis?
This would mean as long as you don't do any external data calls from an OnSelect, the buttons will execute completely in the order in which you've Select-ed them, but if you do any sort of external data calls, other queued Selects will be called, and if two Select calls on the queue have external data calls, then you've introduced a potential race condition.
I don't have any insider knowledge, but it is also my understanding that calls in PowerApps are done in an async fashion. However, I would suggest that is not limited to external calls. One of the issues I hear regularly from people is that App.OnStart won't always create collections or variables before the controls on a screen try to use them. I would suggest this is the same kind of Async behavior where onstart and initial screen load run in parallel and one is not waiting for the load of another. I find it safest to consider everything happening in PowerApps to be Async and program in such a way that things update as data changes.
I reached out to MS and was told the following was true:
I'm not sure conclusions 3 and 4 are correct, Dlabar - or at least they're not the full picture.
(Can't state categorically, I'm only just learning here. And I'm running in an embedded canvas app on a Dynamics 365 CA form. However...)
I've combined two statements in a single button's OnSelect using a semi-colon.
The first statement is a Refresh(someDataSourceOrOther) ; the second is an if statement based on the data in the refreshed datasource.
I've concluded that the If statement is being run before the Refresh has completed, because it evaluates as if it's using values from the previous retrieval. It would appear the Refresh is being set running asynchronously, therefore.
Read the announcement for more information!
Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.
Features releasing from October 2019 through March 2020
Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications