Power Apps Tip – Verify Lists

An ongoing list of examples of developing with Microsoft Power Apps.

Disclaimer


WebDev By The Bay is not affiliated with nor is this post endorsed by any company mentioned in this post. 

All opinions belong to the author of this post.

All Copyrights and Trademarks belong to their respective owners.

Verify List Contents

The listbox on the left is named lbPowerAppsTips , it’s Items property is set to the SharePoint list datasource named PowerAppsTips

The listbox on the right is named lbPowerAppsTipsCollection and its Items property is set to a collection named PowerAppsTipsCollection. The PowerAppsTipsCollection is a copy of the datasource PowerAppsTips.

Copy Datasource to a Collection

Add a button on the canvas and name it btnCopyDataSource

Set btnCopyDataSource Text property to Copy Power Apps Tips

Set btnCopyDataSource onSelect property to

ClearCollect(PowerAppsTipsCollection, PowerAppsTips)

Add a Record to a Collection

Add a button on the canvas and name it btnAddRecord

Set btnAddRecord Text property to ADD

Set btnAddRecord onSelect property to

Collect(PowerAppsTipsCollection, {Title: "Test"})

Verify Lists

Add a button on the canvas and name it btnVerify

Set btnAddRecord onSelect property to

Set btnVerify Text property to VERIFY

Set(
     P1Count,
     CountRows(PowerAppsTips)
 );
 Set(
     P2Count,
     CountRows(PowerAppsTipsCollection)
 );
// This is where we verify the lists
 Set(
     verified,
     ForAll(
         PowerAppsTipsCollection,
         Title in PowerAppsTips.Title
     )
 );
 If(
     Last(verified).Value,
     Set(
         YesNOVerified,
         RGBA(
             0,
             255,
             0,
             1
         )
     ),
     Set(
         YesNOVerified,
         RGBA(
             255,
             0,
             0,
             1
         )
     )
 )

The variables P1Count and P2Count are not critical to verifying the two lists. They are just placeholders for the list item counts of PowerAppsTips and PowerAppsTipsCollection.

The Text property of the labels lblPowerAppsTipsCount and lblPowerAppsTipsCollectionCount are set to the variables.

Show Verification Status

Add a label on the canvas and name it lblVerifyStatus

Set lblVerifyStatus Fill property to the variable we created in the btnVerify onSelect code, YesNOVerified

Set lblVerifyStatus Text property to If(Last(verified).Value, “YES”, “NO”). We created the variable verified in the btnVerify onSelect code also.

We need to use the Last function due to

 Set(
     verified,
     ForAll(
         PowerAppsTipsCollection,
         Title in PowerAppsTips.Title
     )
 );

ForAll returns a table of the results (true or false).

Verified variable now contains a Table
Verified variable now contains a Table

We need to ensure we only verify against the last item in the list, the item we added. This item will only exist in our Collection, it doesn’t exist in the SharePoint datasource just yet.

To save our Collection data to SharePoint we can use either Collect, Patch or Update functions.

References