I have an app that has a lot of necessary code to run OnStart of the app - setting variables/creating collections so the user experience is faster when they use the app.
I have the app going to a welcome screen once the OnStart actions are complete.
I have found that when I include certain ClearCollect statements in the OnStart code it will take nearly 2 mins to get to the welcome screen - If I omit these in the OnStart code it takes less than 5 seconds to get to the welcome screen.
I will display most of the OnStart code first and then the specific ClearCollects that seem to be causing the problem - I think I have rogue code here but Powerapps is not telling me it is so...
Set(
varNewOfficer,
false
);
Set(
varUserMail,
User().Email
);
With(
{_detail: MyDetails},
If(
LookUp(
_detail,
Lower(email) = Lower(varUserMail),
admin
) = true,
Set(
varadmin,
true
)
)
);
ClearCollect(
colContacts,
AddColumns(
BusinessUnits,
"Contact1",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact1],
firstname & " " & surname
)),
"Contact2",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact2],
firstname & " " & surname
)),
"Contact3",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact3],
firstname & " " & surname
)),
"Contact4",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact4],
firstname & " " & surname
)),
"Workphone",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact1],
workphone
)),
"Homephone",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact1],
homephone
)),
"Workmobile",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact1],
workmobile
)),
"Homemobile",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact1],
homemobile
)),
"Workphone2",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact2],
workphone
)),
"Homephone2",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact2],
homephone
)),
"Workmobile2",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact2],
workmobile
)),
"Homemobile2",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact2],
homemobile
)),
"Workphone3",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact3],
workphone
)),
"Homephone3",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact3],
homephone
)),
"Workmobile3",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact3],
workmobile
)),
"Homemobile3",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact3],
homemobile
)),
"Workphone4",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact4],
workphone
)),
"Homephone4",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact4],
homephone
)),
"Workmobile4",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact4],
workmobile
)),
"Homemobile4",
(LookUp(
MyDetails,
personnelno = BusinessUnits[@contact4],
homemobile
))
)
);
ClearCollect(
colTrips,
Trips
);
ClearCollect(
colTripDetails,
TripDetails
);
ClearCollect(
colMyDetails,
MyDetails
);
Navigate(
PRIVACYSCREEN,
Fade
);
running that takes less than 5 seconds..........and now the 2 seemingly problematic bits of code:
ClearCollect(
colGalleryData,
AddColumns(
Trips,
"thetripid",
LookUp(
TripDetails,
tripid = tripid,
tripid
)
)
);
ClearCollect(
colTripData,
With(
{
StartDate: Today(),
EndDate: Today() + 5,
Data: AddColumns(
TripDetails,
"Region",
LookUp(
Trips As aTrip,
aTrip.tripid = tripid
).region
)
},
Filter(
Data,
tripdate >= StartDate,
tripdate < EndDate
)
)
);
for reference the Trips SP list has 657 records and the TripDetails list has 1600 approx so we're not talking huge amounts of data..
@WarrenBelz thanks Warren - that fixed it - it takes 3 seconds now to run the whole thing!
Hi @bobgodin ,
Thanks for the tag - you will need to increase your Delegation limit to 2,000 here and you cannot do this if any of the lists get over this, but two things - try to do it all "locally" as below
With(
{
Details: TripDetails,
Trip: Trips,
StartDate: Today(),
EndDate: Today() + 5
},
ClearCollect(
colGalleryData,
AddColumns(
Trip,
"thetripid",
LookUp(
Details,
tripid = tripid,
tripid
)
)
);
ClearCollect(
colTripData,
AddColumns(
Filter(
Details,
tripdate >= StartDate,
tripdate < EndDate
),
"Region",
LookUp(
Trip As aTrip,
aTrip.tripid = tripid
).region
)
)
);
but the AddColumns in the first bit has me puzzled as you are simply adding the column value you already have (tripid) - why not simply
AddColumns(
Trip,
"thetripid",
tripid
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
MVP (Business Applications) Visit my blog Practical Power Apps
@WarrenBelz Hi Warren - those 2 code blocks above I got your kind assistance with forming - can you cast your eye over them in case I have somehow changed the original content..
Both of those code blocks, when run alone in my StartScreen OnVisible property take nearly 2mins to complete - I get the dataset I need but there's a whole lot of activity in the background - ants crossing the screen continually
I turned the monitor function on and waited for the 2nd ClearCollect to run and finish - it delivered 9 rows (expected) but I think it looked up every single record in the List - any fault finding tips would be most welcome everyone - thanks a lot!
App.OnStart is being deprecated. Consider using Named Formulas for the global variables and putting your collections in the start screen.
If your datasource is Dataverse, there are ways to merge tables without collections.
@Bilakanti thanks but how do I wrap that around all my code in OnStart?
@bobgodin Try using concurrent function, if there are no dependencies with your collections.