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

Refresh button only kicks in second time I click

Hi community,

 

I have an App reading from a SharePoint list and a screen with a Refresh button that is not behaving as I expect. When clicked, it should make a loading message start, refresh the data source, collect the data again in local collections, and finally make the loading message disappear.

In the same screen, I am showing values from the local collections, so I can see straight away if an update has worked.

The loading message works fine, but the data does not refresh the first time I click on the button. I need to click twice for the Refresh and the ClearCollect to run completely (as far as I understand?). 


I don't understand why and appreciate any help 🙂 

I have understood that PowerApps is not always great at understanding  sequence of multiple commands. May that be the problem? What is a good work-around then?

 

 

I have the following code (EU code, so ; instead of , and so on): 

 

Button.OnSelect=

Set(AppLoaded;false);;  <---- the variable AppLoaded makes the loading message visible/invisible
Refresh(ListeAlleUnibuss);;
Concurrent(
ClearCollect(AlnaBusser; Filter(ListeAlleUnibuss; Verksted = "Alnabru"));
ClearCollect(KlemetsrudBusser; Filter(ListeAlleUnibuss; Verksted = "Klemetsrud"));
ClearCollect(RosenholmBusser; Filter(ListeAlleUnibuss; Verksted = "Rosenholm"))
);;
Set(AppLoaded; true)

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Helper I
Helper I

Re: Refresh button only kicks in second time I click

Coming back after some testing, I have found a solution. Maybe not so elegant, but it does the job! 

I found out that the problem was actually not the Refresh, but the ClearCollect. I tested separating the two actions in 2 buttons, but even when ClearCollect was called 5 seconds after the Refresh, it didn't have any effect. It needed to be fired twice to grab the data. So I obliged the App to run ClearCollect twice through a timer. 

Every time the user clicks on the Refresh button, the following runs: 

 

Concurrent(
    Set(AppLoaded; false);  <--- I make a loading animation start
    Refresh(MySharePointList);    <--- I call for a refresh of the sharepoint list
    UpdateContext({CountDown: false});; UpdateContext({CountDown: true})  <---- I make the timer start
);; 
Concurrent(
    ClearCollect(OneListOfBusses; Filter(MySharePointList; Place = "Lillehammer"));  <---- I collect filtered sets of the sharepoint list
    ClearCollect(AnotherListOfBusses; Filter(MySharePointList; Place = "Tønsberg"))

I then have a hidden timer with Duration 3 seconds, and

Timer.Start = CountDown (the boolean kickstarted in the Refresh button)

Timer.OnTimerEnd = Concurrent(
ClearCollect(LillehammerBusser; Filter(ListeAlleUnibuss; Verksted = "Lillehammer"));
ClearCollect(TonsbergBusser; Filter(ListeAlleUnibuss; Verksted = "Tønsberg"))
);;
Set(AppLoaded; true)

In other words, I oblige the app to run ClearCollect again after 3 seconds. This did the trick for me. Still, I don't know why ClearCollect doesn't run the first time xD

 

Case solved, but if you have any ideas on how to do it better, I'd be glad to hear! 🙂

 

View solution in original post

6 REPLIES 6
Highlighted
Community Support
Community Support

Re: Refresh button only kicks in second time I click

Hi @Ginevra ,

Here's a similar problem that someone met for your reference:

https://powerusers.microsoft.com/t5/Expressions-and-Formulas/patching-issue-requires-to-push-the-but...

 

I suggest you split up the formulas. For example, you could set the Refresh funtion to the Screen's OnVisible.

 

 

 

Best regards,

Community Support Team _ Phoebe Liu

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Helper I
Helper I

Re: Refresh button only kicks in second time I click

Hi @v-yutliu-msft ,

 

Unfortunately the other user case you refer to did not help. 

Splitting the formula so one part is in the OnVisible screen property does not solve my case: the user may have this screen open all the time, and want to receive updates if, e.g. the SharePoint list is updated from SharePoint. 

 

In my case, I need PowerApps to first refresh the datasource, then collect it in local collections. Data from these are shown in the screen. I put the two formulas one after the other, separated by ; . 

But it seems to me like PowerApps sometimes jumps over my Refresh command, or does it after the ClearCollect.

Does anyone have a technical understanding of how PowerApps computes sequential commands, and how you can better control it?

 

 

Highlighted
Helper I
Helper I

Re: Refresh button only kicks in second time I click

Coming back after some testing, I have found a solution. Maybe not so elegant, but it does the job! 

I found out that the problem was actually not the Refresh, but the ClearCollect. I tested separating the two actions in 2 buttons, but even when ClearCollect was called 5 seconds after the Refresh, it didn't have any effect. It needed to be fired twice to grab the data. So I obliged the App to run ClearCollect twice through a timer. 

Every time the user clicks on the Refresh button, the following runs: 

 

Concurrent(
    Set(AppLoaded; false);  <--- I make a loading animation start
    Refresh(MySharePointList);    <--- I call for a refresh of the sharepoint list
    UpdateContext({CountDown: false});; UpdateContext({CountDown: true})  <---- I make the timer start
);; 
Concurrent(
    ClearCollect(OneListOfBusses; Filter(MySharePointList; Place = "Lillehammer"));  <---- I collect filtered sets of the sharepoint list
    ClearCollect(AnotherListOfBusses; Filter(MySharePointList; Place = "Tønsberg"))

I then have a hidden timer with Duration 3 seconds, and

Timer.Start = CountDown (the boolean kickstarted in the Refresh button)

Timer.OnTimerEnd = Concurrent(
ClearCollect(LillehammerBusser; Filter(ListeAlleUnibuss; Verksted = "Lillehammer"));
ClearCollect(TonsbergBusser; Filter(ListeAlleUnibuss; Verksted = "Tønsberg"))
);;
Set(AppLoaded; true)

In other words, I oblige the app to run ClearCollect again after 3 seconds. This did the trick for me. Still, I don't know why ClearCollect doesn't run the first time xD

 

Case solved, but if you have any ideas on how to do it better, I'd be glad to hear! 🙂

 

View solution in original post

Highlighted
Resolver I
Resolver I

Re: Refresh button only kicks in second time I click

Hi

 

This was also driving me crazy, your post showed me that I wasn't alone!

After the second refresh the data comes back OK

I'm looking at a SQL data source, and I have a filter on it, when the filter is taken off it works fine, so no need to double refresh. Also issue happens if I try to sort the data
Both Filter and Sort delegate OK to the SQL DB, but suspect issue is because delegation in conjunction with Collections and filters has an issue, I suspect if you take the filters out of your ClearCollect commands it will not need the double refresh (Make sure to take the filtesr out of all ClearCollect commands that are in the same statement)
While this solves my problem, it's not ideal, as I need to apply the filter, so I have to now refresh twice in an APP designed for offline capability, so it slows it down
My workaround maybe to make some views in SQL.... that I can connect to without the use of filters

Let me know if that helps!

 

 

 

Highlighted
Helper I
Helper I

Re: Refresh button only kicks in second time I click

Hei @bkeano , thanks for your reply. I didn't think about that Filter could be the issue, that's noted down!

Highlighted
Advocate I
Advocate I

Re: Refresh button only kicks in second time I click

Long time stale this post, but I found it so maybe someone else might find this useful.

Turning off the experimental feature: "Use longer data cache timeout and background refresh" fixed this for me.

In fact, using the timer to re-cache the data did not work for me when this feature was turned on.

When I turned it off, it started working - on the first refresh and clearcollect - without having to use the timer.

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,726)