Hi all,
I've got a gallery control with a collection as source. The collection is pulled from a SharePoint List at the OnStart of the App. I made a Refresh Button to refresh the collection just in case an other person manipulates the data or adds new records. (I should do something with check out and in)
This is the code of the Refresh Button:
// Refresh data from SharePoint List
Refresh(MTRequest);
// Recreate Collection with refreshed data
ClearCollect(
MTRequest_Col,
MTRequest
);
// Reset the Gallery which selects first row
Reset(glyRequests);
// Reset variables
Set(
varIcons,
{
Stretcher: glyRequests.Selected.MedicalNeedsStretcher,
ExtendedLegrest: glyRequests.Selected.MedicalNeedsExtendedLegrest,
Automatically: glyRequests.Selected.ApproveFormAutomatically,
NurseOnDuty: glyRequests.Selected.ApproveFormByNurseOnDuty
}
);
Code of the Refresh Button when using the timer:
// Refresh data from SharePoint List
Refresh(MTRequest);
// Recreate Collection with refreshed data
ClearCollect(
MTRequest_Col,
MTRequest
);
// Reset the Gallery which selects first row
Reset(glyRequests);
// Reset var to start timer
UpdateContext({goTimer: false});
UpdateContext({goTimer: true});
OnTimerEnd code:
// Reset variables
Set(
varIcons,
{
Stretcher: glyRequests.Selected.MedicalNeedsStretcher,
ExtendedLegrest: glyRequests.Selected.MedicalNeedsExtendedLegrest,
Automatically: glyRequests.Selected.ApproveFormAutomatically,
NurseOnDuty: glyRequests.Selected.ApproveFormByNurseOnDuty
}
);
Can someone please help me understand what is going on here and tell me how I can solve this in a proper way?
Solved! Go to Solution.
Thank you both for your explanation.
I ended up keeping the timer control and also added a spinner animation to inform the user about any delay. Just to be on the save side.
Hello @Power_Robert
Without looking at your data source, this is how I would approach it:
// Refresh data from SharePoint List
Refresh(MTRequest);
// Recreate Collection with refreshed data
ClearCollect(
MTRequest_Col,
MTRequest
);
// Reset the Gallery which selects first row
Reset(glyRequests);
//Set the varSelectedGlyRequest variable.
Set(varSelectedGlyRequest, First(MTRequest_Col));
//Reset variables
Set(
varIcons,
{
Stretcher: varSelectedGlyRequest.MedicalNeedsStretcher,
ExtendedLegrest: varSelectedGlyRequest.MedicalNeedsExtendedLegrest,
Automatically: varSelectedGlyRequest.ApproveFormAutomatically,
NurseOnDuty: varSelectedGlyRequest.ApproveFormByNurseOnDuty
}
);
After you reset the gallery so it could select the first record, I don't think the "selected" action is triggered this way, which could explain why it works the 2nd time the button is clicked. The approach above sets another variable, varSelectedGlyRequest, after the Reset(glyRequests) action. This sets the variable to the first record from the MTRequest_Col collection. Then, when setting the varIcons variable, each property will use the sub-property value of the varSelectedGlyRequest. Eliminate the timer while you test and give it a shot.
Regards,
Hi @faustocapellanj,
This works, thank you.
I just still don't understand why my solution only works when using a timer/delay. Even if it is just one millisecond. There are a lot of (label)controls on the same screen that rely on glyRequests.Selected and they all show their correct value right after the refresh. Only the four icon controls rely on the varIcons, which gets is value also from glyRequests.Selected. But I do notice that any change to the other fields, which I do directly in SharePoint at the moment, shows after a small delay after the reload button is clicked.
I found that it might have something to do with "race condition" as explained at the and of the Concurrent function documentation (which I don not use here).
Can someone confirm this for me please?
Thanks!
The PowerApps documentation will have you believe that Functions and Actions occur in the order in which they are written in the formula bar.
That being said, it is important to understand what constitutes 'performed'
I believe with something like Reset or Refresh, the function will technically complete in the correct order, but their may be cascading ramifications. Especially if you have a Gallery wired up directly to a data source, for example - it will be dependent on bandwidth before the request finishes and potentially is 'complete' by the app controls referencing it. It's something you could explore/test using the Monitor.
Thank you both for your explanation.
I ended up keeping the timer control and also added a spinner animation to inform the user about any delay. Just to be on the save side.
Glad to hear it's working. I normally use spinners when loading or refreshing data so the user knows there's something going on. Please mark the post as solved so a person that might be experiencing the same issue can use this as reference.
Regards,
Stay up tp date on the latest blogs and activities in the community News & Announcements.
Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
User | Count |
---|---|
196 | |
174 | |
62 | |
33 | |
32 |
User | Count |
---|---|
339 | |
270 | |
109 | |
76 | |
59 |