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

Is this run simultaneously?

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
    }
);

 

 

  1. The code for setting the variables for varIcons, is also in de OnSelect of the gallery (glyRequests), but does not run during a reset of the gallery, even though the first row is selected during a reset, and that is why I had to add it to the reload code as well.
  2. I am wondering if all the code above is run at the same time / simultaneously. The variables for varIcons only update on the second time. So it looks like varIcons is set before the refresh of the data source is finished.
  3. When I place a Timer control of even 1 millisecond and move the code to set varIcons at the OnTimerEnd, it is all working fine.

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

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.

View solution in original post

5 REPLIES 5
Highlighted
Memorable Member
Memorable Member

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,

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!
Highlighted

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!

Highlighted
Super User II
Super User II

The PowerApps documentation will have you believe that Functions and Actions occur in the order in which they are written in the formula bar.

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/working-with-formulas-in-depth#more-tha...

 

That being said, it is important to understand what constitutes 'performed'

  • Set - this will complete before the next function
  • Select - this will also complete before the next function
    • However, it is important to understand that the associated Functions on the selected Control are queued up for processing (as though User clicked the control, and it does not wait)
    • This is important, because you cannot (for example) use a Button to hold your loading pattern functions and then 'call' the Button/Functions in a specific order

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.

Highlighted

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.

View solution in original post

Highlighted

Hi @Power_Robert 

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,

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,582)