[TIPS] Collections in PowerApps: Collect, Clear, ClearCollect, ForAll

 [TIPS] Collections in PowerApps:  Collect, Clear, ClearCollect, ForAll

Reference 1 2 3

Collect:

  Collect(collection name, {column name 1: value 1, column name 2: value 2, ....})

 e.g.  

1.  Collect(collCars, {CarName : "A5", CarModel : "Audi", Year : 2022})

2.  For keyboard application, use blow script for OnSelect property of each key.

    Collect(

           colLetters,

          {

                 Text: Self.Text,

                 ID: If(

                           !IsBlankOrError(Last(colLetters).ID),

                           Last(colLetters).ID + 1,

                           1

                     )      

            }

   )

Clear: 

   Clear(collection name)

   This function will clear all data in collection.


ClearCollect:

    ClearCollect(collection name, {column name 1: value 1, column name 2: value 2, ....})

    This function will clear all data in collection firstly, then add new data into collection.

    Or you can use below script to clear and add a blank value.

    e.g.  ClearCollect (collection name, Blank())

  


ForAll:

     ForAll(Datasource Name, Collect(collection name, {column name 1: value 1, column name 2: value 2, ....}))

e.g.    ForAll(Cars, Collect(collCars, {CarName : : "A5", CarModel : "Audi", Year : 2022}))

      ForAll(Filter(Cars, UserId = Value(txtUserId.Text)),  Collect(collCars, {CarName : : "A5", CarModel : "Audi", Year : 2022}))


Remove:

   e.g.  Remove (collection name, Last(colletion name))      

          Remove(ProductList, ThisItem)


No comments:

Post a Comment