cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nurbmr
Helper I
Helper I

ClearCollect or Patch?

Hi, I aim to auto-populate a form from the information retrieved from two QR codes. Below is the flow of what I aim to achieve and what I've done:

  1. QR code 1 is scanned, Split the QR code data string into rows, store them into collection1.
  2. QR code 2 is scanned, Split the QR code data string into rows, store them into collection2. 
  3. Auto-populate Form1, submit to database. 

Step 3 is where I'm stuck. To auto populate the form, should I use Patch or ClearCollect function to merge the two collections? How do I go about this? Is it possible to patch a form with data from collections? I do have other fields in the form that are not included in the previous collections, that need to be entered manually by the user. 

 

Thank you.

11 REPLIES 11
WarrenBelz
Super User III
Super User III

Hi @nurbmr ,

Assuming the two collections have identical field names and types, you can merge them

ClearCollect(
   collection3,
   collection1,
   collection2
)

You cannot however base a Form Item on a record in a collection (it has to be from a List), but you can have individual controls (not in a Form with collection3.FieldName

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz ,

 

The two collections have different field names. I need the information to be in form format for requirement purpose for it to be submitted to the database. Am I right to assume that it's not possible to have individual controls to be submitted as one set of record to the database? What function should I use to auto-populate the form then? 

Hi @nurbmr ,

If you go to my other suggestion of individual controls on a screen (not in a Form), you could put whatever you want in any of them (from either Collection). You could then Patch the lot (as individual values) as a new record to your List.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

WarrenBelz
Super User III
Super User III

HI @nurbmr ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz ,

Thank you for your suggestion! What I've done was put two galleries showing the information based on the QR code scanned and add two more individual controls for the other columns in the database (name: SAMPLEFORM) table. However, I encounter some problems, which are:

1. The more codes I scan, the gallery expands, which is understandable. How do I limit to only display the record associated with the code scanned? 

2. The information displayed in the galleries and the individual controls cannot be submitted to the database (name: SAMPLEFORM). Why? 

 

Below is what I have in each component:

1. Gallery_User 

Items: SAMPLEDEETS <- database

Labels: Label_ID, Label_FirstName, Label_LastName

 

2. Gallery_Comp

Items: SAMPLECOMP <- database

Labels: Label_Item, Label_PartNumber, Label_Description

 

3. TextInput3_RefNumber

 

4. Dropdown5_Status

 

5. Submit button OnSelect property

Patch(SAMPLEFORM,Defaults(SAMPLEFORM),{Item:Label_Item, PartNumber:Label_PartNumber,Description:Label_Description,ID:Label_ID, FirstName:Label_FirstName, LastName:Label_LastName,Status:Dropdown5_Status.Selected.Value,ReferenceNumber:TextInput3_RefNumber.Text})

 Thanks 

Hi @nurbmr ,

To limit the gallery to the current item, use ClearCollect instead of Collect.

I also suggested unbound controls, not a gallery, but you need a different approach here if you are going to use a gallery with one item.

Also you need .Text after the label names and you should not be Patching ID to a list as it is auto-created. As well any numeric fields need to be wrapped in Value(). This may not be totally correct as I cannot see your data or controls, but would be something like

With(
   {wItem:First(YourGalleryName.AllItems)},
   Patch(
      SAMPLEFORM,
      Defaults(SAMPLEFORM),
      {
         Item:wItem.Label_Item.Text, 
         PartNumber:wItem.Label_PartNumber.Text,
         Description:wItem.Label_Description.Text, 
         FirstName:wItem.Label_FirstName.Text, 
         LastName:wItem.Label_LastName.Text,
         Status:wItem.Dropdown5_Status.Selected.Value,
         ReferenceNumber:wItem.TextInput3_RefNumber.Text
      }
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz , 

I've decided to use gallery as my QR code is directly related to my database, with only primary key. Using gallery allows all the data related to the QR code scanned to be displayed.

 

On BarcodeScanner1, my OnScan property is 

Set(V1,BarcodeScanner1.Value)

And on Gallery, Items property is 

Filter(Database1,V1=Value1)

This appears to work well, so far. 

 

The ID in this is, in the context of my project, the User's ID, stored in the database, not the PowerApps auto-generated ID. I assume it's okay to patch it to the form then? 

@nurbmr ,

If you are adding a new record, the ID will be auto-generated and you will not be able to see it until you look at the record after it is created. You simply need to Patch the matching fields from the gallery to the List.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

WarrenBelz
Super User III
Super User III

Hi @nurbmr ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,295)