OK gurus of PowerApps -- need your wisdom once again.
Details:
Questions:
Thanks in advance!
LO AND BEHOLD - after MUCH wailing and gnashing of teeth - I figured out what the problem was. I was right! There was no problem with my code. The problem was an experimental app setting I had turned on, thinking it sounded like a good idea. NOT! At least not for this app. The problem child was "Use longer data cache timeout and background refresh." As soon as I turned it off, things started working correctly. Even a forced refresh prior to the collection load appeared to be ignored which caused the data to be incorrect in the collection.
That is some crazy formula you've got there...how did you come up with something that crazy? LOL (for those observing this message - we collaborated on this through some private messages 😉 )
So, you are saying that your testing by adding a variable to the OnVisible did in fact update properly, but the multiList collection is NOT getting updated? So from the Patch function and the datasource from the EditForm, you are patching and updating NextSteps and Audit datasources.
In your formula, the first "build" of the multiList is entirely based on the PA datasource. I'm suspicious about the second "amendment" to the multiList that is based on the NextSteps datasource.
My suspicion is that something in that NextSteps part is not executing as expected...or really, that it is, but not yielding what you might think.
It's rather difficult to troubleshoot this one without the data and sample, so, I can provide some suggestions...
1) Add some time stamp columns in multList - dTime : Now()
Check those immediately after page OnVisible in the Collection viewer. They should update each time.
2) Pull the second NextSteps part out of the formula completely and see if there is a change (in the collection...I expect there would be in your app). Same for the first part based on PA.
Other considerations...personally I would pull this entire formula out of the OnVisible property and put it in its own place. It seems the two formulas, for PA and for NextSteps, can stand on their own apart from each other (not sure on this...you know your data better) because they both feed new items to multList.
I would put the formulas in a Toggle control's OnCheck property and use a variable to "fire" the building of the collection when needed (ex. in OnVisible, or after a form is submitted etc.) This would give you much greater control of that formula and would move it into some place easier to troubleshoot.
Just some suggestions.
I can find no conditionals or errors which would prevent the update. I have used a label to verify that the On Visible IS being invoked -- but the collection is NOT being updated when returning from the update on Screen 2. I have tried forcing a refresh of the list when leaving Screen 2, but Screen 1 still does not update. I have tried returning to Screen 1 with a Navigate rather than a Back, but Screen 1 still does not update. Yet when I exit from Screen 1 to the Home Page and invoke Screen 1 again, it DOES update.
Here's the On Visible code:
Set( RptPopUpVisible, false ); Set(StartDate,DateAdd(dpWeekEndDate.SelectedDate,-6)); Clear(multiList); // Skeleton structure of what is about to happen: // // ForAll(shaped and grouped Data, // collect-departments into multiList; // ForAll(projects in department groups, // collect-projects into multiList; // ForAll(stones in project groups, // collect-Accomp into multiList // ) // ) // ) ForAll( //We need to group two levels - one for the inner accomplishments grouped by Department and Project (records are the (Accomp)lishments) //We need to compare a few things in the later levels, so we also need to add the department and project in the // appropriate places - this will speed up the lookups in the ForAlls SortByColumns( GroupBy( SortByColumns( AddColumns( GroupBy( AddColumns( SortByColumns( Filter( PA, Archive = false ), "Title" ),//Sort the list so Accomplishments (PA) are in order "dep", DepartmentName.Value, "proj", ProjectName.Value ),//AddColumns - Put the dep and proj on the records of all milestones "dep", "proj", "accomp" ),// LEVEL 2 GroupBy - group by the department and project and give us a table of accomp "depL2", dep ),// AddColumns add the department at LEVEL 2 as well (but a different name) "proj" ),// SortBy Project Column "depL2", "Projects" ),// LEVEL 1 GroupBy - finally group by the Department with a table of projects "depL2" ),// SortByColumns - Sort by Department Column //The stage is set....Now lets collect some records // DEPARTMENTS // Here we are on the outside of the groups - we have a Department column and a table column of Project Records // REMEMBER: we are in a ForAll function - this is the FIRST statement of the ForAll...a Collect function Collect( multiList, //Every record in our final collection should have a DataLevel (used only during this compilation, a DepLevel, which is the caclulated Department //level, a Project Level - a calculation of the project level, and a milestonelevel - also calculated { DataLevel: 1, // we use the datalevel for our filter statements only, this is level 1 DeptLevel: CountRows(Filter(multiList, DataLevel = 1)) + 1, //count the number of rows in our collection that are at this datalevel, we should be the next one ProjLevel: 0, // we're at the department level now, so all records have 0 project PALevel: 0, // we're at the department level now, so all records have 0 PA myDept: depL2, //and of course, the real data...the department name at this point is all we care about sortKey: Text(CountRows(Filter(multiList, DataLevel = 1))+ 1,"[$-en-US]000") & "000" & "000" } ); // PROJECTS // Now lets collect with the Departments' Projects - here we go into the Projects tables of the group // REMEMBER: we are in a ForAll function - this is the SECOND (and last) statement of the outer ForAll...this final statement is a ForAll // Here we are working with the Projects table column from the outer group LEVEL 1 ForAll( Projects, Collect( multiList, { DataLevel: 2, // we use the datalevel for our filter statements only, this is level 2 DeptLevel: LookUp(multiList, myDept = dep).DeptLevel, // in this level, we look up the department level for this department that was collected before ProjLevel: CountRows(Filter(multiList, DataLevel = 2)) + 1, // count the number of rows in our collection that are at this datalevel, we are the next one PALevel: 0, //we're at the project level now, so 0 PA myDept: depL2, //and of course, the real data...the department name myProject: proj, // and the project name sortKey: Text(LookUp(multiList, myDept = dep).DeptLevel,"[$-en-US]000") & Text(CountRows(Filter(multiList, DataLevel = 2)) + 1,"[$-en-US]000") & "000" } ); Collect( multiList, { DataLevel: 3, // we use the datalevel for our filter statements only, this is level 2 DeptLevel: LookUp(multiList, myDept = depL2).DeptLevel, // in this level, we look up the department level for this department that was collected before ProjLevel: CountRows(Filter(multiList,DataLevel = 2)), // we look up the project level for this project that was collected before PALevel: 1, //we're at the project level now, so 0 PA myDept: depL2, //and of course, the real data...the department name myProject: proj, // and the project name PA: "Accomplishments", PAType: " ", sortKey: Text(LookUp(multiList,myDept = depL2).DeptLevel,"[$-en-US]000") & Text(CountRows(Filter(multiList, DataLevel = 2)),"[$-en-US]000") & "001" } ); // ACCOMPLISHMENTS // we are in the Projects grouping...so let's grab the Accomp as well now // REMEMEBER: We are the second statement in the Last statement of the outer ForAll // Here we are working with the Accomp table column from the inner group LEVEL 2 ForAll( Projects[@accomp], Collect( multiList, { DataLevel: 3, // we use the datalevel for our filter statements only, this is level 3 DeptLevel: LookUp(multiList, myDept = dep).DeptLevel, // in this level, we look up the department level for this department that was collected before ProjLevel: CountRows(Filter(multiList, DataLevel = 2)), // we look up the project level for this project that was collected before //now count the rows that are associated with the dept and proj - we are the next one. PALevel: CountRows(Filter(multiList, myDept = depL2 && myProject = proj && DataLevel = 3)), // And finally, all the real data that we need for the final list myDept: depL2, myProject: proj, PA: Title, PAD: AdditionalDetail, PAType: "A", RptDate: StatusDate, ID: ID, sortKey: Text(LookUp(multiList, myDept = dep).DeptLevel,"[$-en-US]000") & Text(CountRows(Filter(multiList, DataLevel = 2)),"[$-en-US]000") & Text(CountRows(Filter(multiList, myDept = depL2 && myProject = proj && DataLevel = 3)),"[$-en-US]000") } )//end of accomp Collect )// end of accomp ForAll )// end of Projects ForAll ); // end of grouped ForAll //REPEAT THE ENTIRE PROCESS FOR NEXT STEPS BUT ONLY WRITE OUT THE NEXT STEPS HEADER AND DATALEVEL 3 RECORDS //We need to group two levels - one for the inner next steps grouped by Department and Project (records are the Steps) //We need to compare a few things in the later levels, so we also need to add the department and project in the // appropriate places - this will speed up the lookups in the ForAlls ForAll( SortByColumns( GroupBy( SortByColumns( AddColumns( GroupBy( AddColumns( SortByColumns( Filter( NextSteps, Archive = false ), "Title" ),//Sort the list so NextSteps are in order "dep", DepartmentName.Value, "proj", ProjectName.Value ),//AddColumns - Put the dep and proj on the records of all NextSteps "dep", "proj", "Steps" ),// LEVEL 2 GroupBy - group by the department and project and give us a table of Steps "depL2", dep ),// AddColumns add the department at LEVEL 2 as well (but a different name) "proj" ),// SortBy Project Column "depL2", "Projects" ),// LEVEL 1 GroupBy - finally group by the Department with a table of projects "depL2" ),// SortByColumns - Sort by Department Column //The stage is set....Now lets collect some records // PROJECTS // Now lets collect with the Departments' Projects - here we go into the Projects tables of the group // REMEMBER: we are in a ForAll function - this is the SECOND (and last) statement of the outer ForAll...this final statement is a ForAll // Here we are working with the Projects table column from the outer group LEVEL 1 ForAll( Projects, Collect( multiList, { DataLevel: 3, // we use the datalevel for our filter statements only, this is level 2 DeptLevel: LookUp(multiList,myDept = depL2).DeptLevel, // in this level, we look up the department level for this department that was collected before ProjLevel: LookUp(multiList, myDept = depL2 && myProject = proj && DataLevel = 2).ProjLevel, // we look up the project level for this project that was collected before PALevel: CountRows(Filter(multiList, myDept = depL2 && myProject = proj && DataLevel = 3)), //we're at the project level now, so 0 PA myDept: depL2, //and of course, the real data...the department name myProject: proj, // and the project name PA: "Next Week", PAType: " ", sortKey: Text(LookUp(multiList, myDept = depL2).DeptLevel,"[$-en-US]000") & Text(LookUp(multiList, myDept = depL2 && myProject = proj && DataLevel = 2).ProjLevel,"[$-en-US]000") & Text(CountRows(Filter(multiList, myDept = depL2 && myProject = proj && DataLevel = 3)),"[$-en-US]000") } ); // NEXT STEPS/NEXT WEEK // we are in the Projects grouping...so let's grab the Steps as well now // REMEMEBER: We are the second statement in the Last statement of the outer ForAll // Here we are working with the Steps table column from the inner group LEVEL 2 ForAll( Projects[@Steps], Collect( multiList, { DataLevel: 3, // we use the datalevel for our filter statements only, this is level 3 DeptLevel: LookUp(multiList, myDept = dep).DeptLevel, // in this level, we look up the department level for this department that was collected before ProjLevel: LookUp(multiList, myDept = depL2 && myProject = proj && DataLevel = 2).ProjLevel, // we look up the project level for this project that was collected before //now count the rows that are associated with the dept and proj - we are the next one. PALevel: CountRows(Filter(multiList,myDept = depL2 && myProject = proj && DataLevel = 3)), // And finally, all the real data that we need for the final list myDept: depL2, myProject: proj, PA: Title, PAD: AdditionalDetails, PAType: "N", RptDate: StatusDate, ID: ID, sortKey: Text(LookUp(multiList, myDept = dep).DeptLevel,"[$-en-US]000") & Text(LookUp(multiList, myDept = depL2 && myProject = proj && DataLevel = 2).ProjLevel,"[$-en-US]000") & Text(CountRows(Filter(multiList, myDept = depL2 && myProject = proj && DataLevel = 3)),"[$-en-US]000") } )//end of Steps Collect )// end of Steps ForAll )// end of Projects ForAll ); // end of Group ForAll
The OnSelect that applies the update on screen 2 is:
Patch(Audit,Defaults(Audit),{Title:"Next Steps",UpdateDate:Now(),DepartmentName:{Id:LookUp(Department, Dept in Title,ID),
Value: Dept,'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"},
ProjectName:{Id:LookUp(Projects, Proj in Title,ID),
Value: Proj,'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"}});
SubmitForm(EditNext);Patch(Department,First( Filter( Department, Title = Dept ) ), { DataLastUpdt: Today() } )
And the Success event for the form is simply:
I just can't find anything that should be causing this to occur...
Questions:
Isn't the On Visible supposed to fire each time Screen 1 becomes visible?
Yes, and it does. I would reinvestigate that you don't have something that is causing it NOT to execute. A conditional statement, an error in the actual formula, etc.
Do I need to also patch the collection with the change at the same time I process the Submit form? I would not have expected to do this as I would have thought the On Visible would simply rebuild with the latest information when I did the Back.
Depends - if you are NOT going to refresh and rebuild the collection after you submit or alter the datasource, then you will need to submit and alter the collection at the same time.
What you expect is correct...if the OnVisible is rebuilding the collection, then you need not add to the collection.
What else can I do to insure the gallery reflects the change when I return to Screen 1?
Double check that you are not conditionally excluding the OnVisible actions. Also, for tests, consider setting a variable in the OnVisible like : UpdateContext({aNumber: aNumber+1}) then putting a label on the screen with aNumber as its text property.
I hope this helps lead to a revelation.
WarrenBelz
637
Most Valuable Professional
stampcoin
570
Super User 2025 Season 2
Power Apps 1919
473