cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ginevra
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

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

7 REPLIES 7
v-yutliu-msft
Community Support
Community Support

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.

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?

 

 

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

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!

 

 

 

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

Jj999999
Advocate I
Advocate I

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.

 

Thanks for taking the time to update this post. You really helped me out. Turns out that experimental feature is present in older ( pre mid 2020??) versions. Today if you turn it off, it disappears from Advanced Experimental Features. Its default status in the older apps is apparently Enabled as it is Enabled in our other apps.

I had a formula on a Button that did a Patch to a large SharePoint list and did an UpdateIf and a RemoveIf to a smaller list. On the first click the UpdateIf and RemoveIf would execute, but not the Patch. If you clicked the Button a second time the Patch executed. Chased my tail for a long time on this. When I turned off the Experimental Feature you named, the Formula worked as intended. Thanks Again.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (73,952)