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

Playing with Collections

Hi All, 

 

Im attempting to build in some offline functionality for an app that uses sharepoint lists as data source. I have some questions regarding collections.

 

  1. Can I create a structure for a collection (ie initialise) without actually collecting a row? Currently collecting a row with a UID and blank values to initialise the structure.
  2. How can I update a row in a collection? Currently I am removing the row with RemoveIf, then re-collecting the 'updated' row.

The plan is to end up with a table/collection that is then synced with appropriate lists. 

 

Cheers

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Playing with Collections


 

  1. Can I create a structure for a collection (ie initialise) without actually collecting a row? Currently collecting a row with a UID and blank values to initialise the structure.

Yes - as long as you have an expression with Collect or ClearCollect somewhere in the application, even if it's never executed, then the collection is "created" - it won't have any data, but its structure will be defined. For example, if you add a button with this formula on its OnSelect property:

ClearCollect(coll, {UID:"",Value:12.34,IsGood:true})

It will define a collection called 'coll' with three columns: UID (type text), Value (type number) and IsGood (type boolean) - even if you never click that button (in which case the collection will be empty).

 

Another thing that you can do, if you want the local collection to have the same schema (structure) as a connected data source: use again a Collect or ClearCollect expression (even if you never invoke it) passing the data source as the second parameter. For example, if I have a table in SQL called '[dbo].[Products]', I can initialize a collection with the same schema by defining this expression:

ClearCollect(coll2, '[dbo].[Product]')

 


  1. How can I update a row in a collection? Currently I am removing the row with RemoveIf, then re-collecting the 'updated' row.

You can use the Patch function for local collections as well.

View solution in original post

1 REPLY 1
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Playing with Collections


 

  1. Can I create a structure for a collection (ie initialise) without actually collecting a row? Currently collecting a row with a UID and blank values to initialise the structure.

Yes - as long as you have an expression with Collect or ClearCollect somewhere in the application, even if it's never executed, then the collection is "created" - it won't have any data, but its structure will be defined. For example, if you add a button with this formula on its OnSelect property:

ClearCollect(coll, {UID:"",Value:12.34,IsGood:true})

It will define a collection called 'coll' with three columns: UID (type text), Value (type number) and IsGood (type boolean) - even if you never click that button (in which case the collection will be empty).

 

Another thing that you can do, if you want the local collection to have the same schema (structure) as a connected data source: use again a Collect or ClearCollect expression (even if you never invoke it) passing the data source as the second parameter. For example, if I have a table in SQL called '[dbo].[Products]', I can initialize a collection with the same schema by defining this expression:

ClearCollect(coll2, '[dbo].[Product]')

 


  1. How can I update a row in a collection? Currently I am removing the row with RemoveIf, then re-collecting the 'updated' row.

You can use the Patch function for local collections as well.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,267)