web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / ForAll into Collection...
Power Apps
Unanswered

ForAll into Collection but grab additional data from a Lookup

(0) ShareShare
ReportReport
Posted on by 219

Hello,

 

I'm in need of some help please, I have a barcode scanner which on the "OnScan" option i have the following code:

ForAll(
 BarcodeReader1.Barcodes,
 Collect(
 GetLinkedBarCodes,
 {Barcodes: ThisRecord.Value}
 )
);

Here I'm placing each barcode value into a collection with the column being called "Barcodes". 

What I'd like to do is when it adds the records to the collection it also does a lookup from a Sharepoint list for each of the barcodes and brings back a column from the record which i can also add to the Collection for each record in the collection.

 

For example:

ForAll(
 BarcodeReader1.Barcodes,
 Collect(
 GetLinkedBarCodes,
 {Barcodes: ThisRecord.Value,
 Assigned_To: LookupData.FullName}
 )
);

Output:

BarcodesAssigned_To
123456Mike
987654321Gabriella
5654345Stephen

 

But I'm not sure where to put this lookup within the ForAll/Collect code, or even if its possible.

 

Any suggestions/help would be much appreciated. Thank you in advance.

Categories:
I have the same question (0)
  • BCBuizer Profile Picture
    22,510 Super User 2025 Season 2 on at

    Hi @CCEP_Mike ,

     

    Please try this:

    ForAll(
     BarcodeReader1.Barcodes,
     Collect(
     GetLinkedBarCodes,
     {Barcodes: ThisRecord.Value,
     Assigned_To: LookUp(SharePointList, BarcodeColumn = ThisRecord.Value, Assigned_ToColumn)}
     )
    );

     

    What it does, is to use a LookUp function to see if there is an existing item in you SharePointList in the BarcodesColumn and return value from the Assigned_ToColumn.

     

    For this to work, replace the list and column identifiers with the actual names.

     

    If you the Assigned_ToColumn is a Person/Group type column you have to add .DisplayName after the name of the column.

  • CCEP_Mike Profile Picture
    219 on at

    Hi @BCBuizer ,

     

    Thank you for your response, I've tried doing it this way prior to writing this thread, how ever I kept getting an error message in the code. I've copied your code and tried again just now in case i did my code wrong but I'm getting the same issue. See image below:

     

    error.PNG

    It doesn't seem to like using the "ThisRecord.Value" a second time for some reason.

     

    Any suggestions would be much appreciated. Thank you.

  • timl Profile Picture
    36,415 Super User 2025 Season 2 on at

    Hi @CCEP_Mike 

    The most likely cause of this is that ThisRecord will be scoped to the Parcels data source in the call to LookUp. You might have more success calling AddColumns (plus it'll be more efficient).

    AddColumns(BarcodeReader1.Barcodes, 
     Assigned_To, 
     LookUp(Parcels,Barcode=Value).'To-CCEP' 
    )

    Provided that doesn't result in any errors, you can call RenameColumns to rename 'value' to Barcodes and call Collect to collect the result to GetLinkedBarCodes.

  • CCEP_Mike Profile Picture
    219 on at

    Hi @timl ,

     

    Thanks I'll give this a try, where do i place this code? I've tried placing it within the ForAll/Collect code but i cant seem to get it to work without error message. I could be wrong but i feel it needs to sit within the Collect part otherwise how will it know which Collection it needs to add the new column to?

     

    Any support would be much appreciated. Thank you.

  • timl Profile Picture
    36,415 Super User 2025 Season 2 on at

    Hi @CCEP_Mike 

    In the OnScan property of the barcode reader, I would add the following.

    Collect(
     GetLinkedBarCodes_Test,
     AddColumns(BarcodeReader1.Barcodes, 
     Assigned_To, 
     LookUp(Parcels,Barcode=Value).'To-CCEP' 
     )
    )

     

    If there are no errors and the assigned value appears correctly in the GetLinkedBarCodes_Test collection, we can then modify the formula so that it operates more closely with the original formula that you posted. 

  • CCEP_Mike Profile Picture
    219 on at

    Hi @timl ,

    Thank you, I've implemented the code how ever I've come into an issue today where when i press the Barcode button, its no longer providing a dummy record within Desktop and instead just displaying a warning say:

    "To read barcodes, open this app in the Power Apps mobile app on a capable device. Click here to view device requirements and learn more.".

    So I wont be able to review the collection and the data that's contained within it since no dummy data is being stored 😞

     

    But theres no errors in the code you've provided, so lets proceed to the next step and then I'll be able to test on Mobile and see if its working as expected as I'll output the value of "Assigned To" for each barcode.

  • CCEP_Mike Profile Picture
    219 on at

    Hi @timl,

     

    I've got this working using the below (I've added a few additional columns, thank you for your help on this!)

     

    ForAll(
     BarcodeReader2_2.Barcodes,
     Collect(
     GetLinkedBarCodes2,
     AddColumns(BarcodeReader2_2.Barcodes, 
     Assigned_To, 
     LookUp(Parcels,Barcode=Value).'To - CCEP',
     Internal, 
     LookUp(Parcels,Barcode=Value).'To - Internal',
     Assigned_To_External, 
     LookUp(Parcels,Barcode=Value).'To - Full Name'
     )
     )
    );

     

    How ever, if i scan 2 barcodes (Scanning Mode = Scan Multiple) then its adding the data to the Collection twice, if i scan 3 barcodes then the same record is created three times (9 records total) within the collection. Do you have any advice for this please?

  • BCBuizer Profile Picture
    22,510 Super User 2025 Season 2 on at

    Hi @CCEP_Mike ,

     

    Because of the ForAll function, for each of the items in in BarcodeReader2_2.Barcodes, the entire list of barcodes (with added columns) gets added which results in duplicates. Removing the ForAll function and replacing Collect with ClearCollect will result in a behaviour where every time a new barcode gets scanned, the collections will be completely refreshed without duplicate records:

    ClearCollect(
     GetLinkedBarCodes2,
    		AddColumns(
    			BarcodeReader2_2.Barcodes, 
    			Assigned_To, 
    			LookUp(Parcels,Barcode=Value).'To - CCEP',
    			Internal, 
    			LookUp(Parcels,Barcode=Value).'To - Internal',
    			Assigned_To_External, 
    			LookUp(Parcels,Barcode=Value).'To - Full Name'
    		)
     )
    );

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard