Can you use ClearCollect to using OnStart? I want to create 4 collections when the app starts. I am connecting to a database and since PowerApps cannot use views or stored procedures, which is very unfortunate, I have to create 4 collections and joining them to get my source for my gallery object. Currently I am using a button and the OnSelect event to populate the collections. But this is an extra step. It would more user friendly is I could create those collections as soon as the app opens up.
Solved! Go to Solution.
@jehrenfeld Is your database using SQL Online or SQL OnPremises? I'm not even sure that it matters, but want to take note.
The main difference I see between what I did and what you are trying to do is that I did not have the conditional rule. I just put a call directly to 'ClearCollect(...)' in the Screen's OnStart rule. I should also note that PowerApps informs me of an error when I try to use the ClearCollect function in the conditional rule as an action. PowerApps gives me the error saying "Function 'ClearCollect' is not supported by Rules Panel". Can you try just calling the ClearCollect functions without the 'IsBlank' conditional? You shouldn't need the 'IsBlank' conditional since you're clearing the collection first with ClearCollect anyways.
If removing the conditional doesn't work, can you try just making one ClearCollect call instead of all 4? I'm just trying to simplify the problem to see what could possibly be the issue. Thanks.
Thanks for getting in touch with the problem. Yes, you can use the clearCollect function onStart of the app. You should be able to find the onStart option on the first screen of the app. Select screen, Select OnStart from dropdown and set the property value to the function you would like to use.
Let me know if this doesn't work for you.
I just added a 'ClearCollect(col, datasource)' rule to the Screen's OnStart rule and the collection, 'col', was populated with the data after launch. In fact, I noticed that app launch was blocked (shows splash scrren) until the http request to retrieve the datasource data had completed. I tried this with SharePointOnline and SQL datasources. What type of datasource(s) are you using? What does your OnStart rule look like?
I am accessing a SQL Database.
I created a rule on the home screen: IsBlank('Home Gallery') Then OnStart : ClearCollect(...).
Home Gallery is my Gallery on the home screen that is bound to one of the collections.
Hi, just throwing in something I learned over time which may help here as well:
When you have an OnStart action it will not run when you preview the app from Studio or Web editor. It will when you launch the app through a phone though. For this reason, whenever I use OnStart in an app while developing it, for testing purposes I create a button with the same function on OnSelect that I can click when previewing the app. Hope that makes sense..
@jehrenfeld, it seems that you marked your question as solved. Can you try to undo this so we know your question is not solved?
Can you provide the full OnStart rule that you are using? You can also try adding the function call 'Refresh(datasource);' at the begining of your OnStart rule to manually trigger a refresh of the datasource.
I created a button that loads runs the below code and it works fine so I know my collection tables are all valid:
attached it the rule
Here is the OnStart on the home screen:
If(LoadCollections, ClearCollect(EmployeeTable,Filter('[dbo].[Employees]', STATUS = 1 And CONTRACTOR <> "1"));
ClearCollect(AWSTable,Filter('[dbo].[ApprovalWorkflowSystem]', sAppName = "Travel Request" And sAppReviewer = txtUserRenumber.Text));
ClearCollect(TravelRequestTable,Filter('[dbo].[USAA_travelrequest]', ISTATUS = 0));
ClearCollect(ApproverList,AddColumns(AWSTable,"EmpName",LookUp(EmployeeTable,RENUMBER = AWSTable[@sAppOwner])))
Continue your learning in our online communities.
Features releasing from October 2019 through March 2020
Coming to a city near you
Fill out a quick form to claim your user group badge now!
Connect, share, and learn with your peers year-round
Register by September 5 to save $200