cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
jehrenfeld
Level: Powered On

ClearCollect OnStart

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff AllenKim
PowerApps Staff

Re: ClearCollect OnStart

@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.

19 REPLIES 19
shmemane
Level: Powered On

Re: ClearCollect OnStart

Hi jehrenfeld,

 

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.

jehrenfeld
Level: Powered On

Re: ClearCollect OnStart

I tried doing that but it does not work. I even did what others had suggested and closed the app and reopened and the collection does not get populated. Have you confirmed that you can connect to a database table and use collect to get the data from the table using the Screen .OnStarrt event?
PowerApps Staff AllenKim
PowerApps Staff

Re: ClearCollect OnStart

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?

jehrenfeld
Level: Powered On

Re: ClearCollect OnStart

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.

DanielaH
Level 8

Re: ClearCollect OnStart

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..

 

Capture.PNG

PowerApps Staff AllenKim
PowerApps Staff

Re: ClearCollect OnStart

Thank you for pointing this out, @DanielaH.

 

@jehrenfeld Can you confirm you tried opening the app in one of our Players (Android, iOS, WebPlayer - https://web.powerapps.com/)?

jehrenfeld
Level: Powered On

Re: ClearCollect OnStart

I have done this several times and it still does not work

PowerApps Staff AllenKim
PowerApps Staff

Re: ClearCollect OnStart

@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.

jehrenfeld
Level: Powered On

Re: ClearCollect OnStart

11-22-2017 2-08-10 PM.jpgI 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])))
)

 

 

 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 53 members 4,877 guests
Please welcome our newest community members: