I have a problem with a groupby-filter combination in a timekeeping app.
I have a screen where the user can select a period, a hidden control contains the username. A gallery shows the hours per day for the user in the selected period, using a GroupBy and Filter. Working fine.
In the screen's OnVisible I use essentially the same code to show last week's hours so the gallery is filled when the user opens the screen (so the only difference is the code for the time period). However, in this case it refuses to filter on the username, and shows the hours per day for all users.
I tried a filter on the main table in advance, but even then, the RegelsPerDag collection shows all users.
My code:
UpdateContext({
DatumVanVullen:DateAdd(Today(), -1 * (Weekday(Today(), Monday) - 1)-7, Days),
DatumTotVullen:DateAdd(Today(), -Weekday(Today(), Monday), Days)});
ClearCollect( RegelsPerDag, GroupBy( Filter(tblTijdschrijfregel, MedewerkerAccessID= MijnMedewerkerAccessID, Datum >= DatumVanVullen, Datum < DatumTotVullen), "Datum", "Regels" ) );
ClearCollect( SomUrenPerDag, AddColumns( RegelsPerDag, "Uren", Sum(Regels, TijdsduurGewogenIntern ) ) );
ClearCollect( UrenPerDag, DropColumns(SomUrenPerDag, "Regels"));
Any idea what may be causing this weird behaviour in the onVisible? I'm stumped, because the code works correctly when started from the controls on the screen.
Thank you for trying :-).
Yes I unfortunately can't answer why this isn't working - this should work and I couldn't replicate the issue 😞
If you have a workaround that's great, hopefully someone else will have an explanation to add here
Yes, the variable is set in onStart. However, this screen is not the Startscreen, so it is not shown directly after startup; and the problem occurs even when the app has been on for a while (e.g. the user has entered some time-keeping records, and then has a look at their totals). Other screens use the same variable, and have no issues.
I also tried pre-filtering the collection by adding a line of ClearCollect(RegelsPerMedewerker, Filter(etc)); on top and then using the GroupBy on the RegelsPerMedewerker. Looking at the collections from the designer, I could see RegelsPerMedewerker containing the expected records, and RegelsPerDag still having unfiltered records.
Right now, my temporary solution is hiding the gallery until a control is selected but I want to understand what is going wrong.
MedewerkerAccessID= MijnMedewerkerAccessID
I assume from the above that MijnMedewerkerAccessID is the variable and MedewerkerAccessID is the column in the datasource?
If you are setting this MijnMedewerkerAccessID during the App OnStart, your OnStart may not have completed when the page became visible.
The non-blocking OnStart setting for an App makes the OnVisible and OnStart run in parallel.
Could you provide some more info around how that variable is generated?
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional