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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch and ForAll to cr...
Power Apps
Answered

Patch and ForAll to create new records

(0) ShareShare
ReportReport
Posted on by 59

Hi,

 

I am new to PowerApps and have some issues with using Patch and ForAll. I have a form where a user enters in some information, one of which is a ComboBox with a list of locations and another (invisible) field where the submitted form gets an ID number (DataCardValue3) based on the existing records in an Excel table (ExampleTable1). My goal is that if a user selects 4 sites for examples, 4 new records are created with all of the same information EXCEPT different ID numbers (sequential) and different Location names. My issue is that I am unable to get the correct number of records created, let alone have the data updated. Within the Patch function I didn't include all of the columns of ExampleTable1 but I'd imagine the code is something along the lines of {Name: textboxName.Text , Age: textboxAge.Text}.

 

For example,

User Inputs into Form3:

            Name: Billy House

            Age: 34

            Location (ComboBox2): New York, Chicago, Paris

 

Output in ExampleTable1:

IDNameAgeLocation
1001Joe Pringles24Tokyo
1002Cheddar Chips72London
1003Billy House34New York
1004Billy House34Chicago
1005Billy House34Paris

 

This example only is with 4 columns, but my actual dataset has 20+ columns. Currently the code is only adding the first record and the rest are ignored. Any help with figuring out how to create multiple records and updating only these two fields would be appreciated! 

 

 

 

 

 

ForAll(
 ComboBox2.SelectedItems, //ComboBox2 contains list of locations that user can choose
 Patch(
 ExampleTable1,
 Defaults(ExampleTable1),
 {
 ID: DataCardValue3 + 1, //DataCardValue3 is where an ID is automatically added to ExampleTable1
 Location: ComboBox2.Selected.'Location Name'
 },
 Form3.Updates,
 )
);
Refresh(ExampleTable1);
ResetForm(Form3)

 

 

 

 

 

 

Categories:
  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @AgarDoge How does DataCardValue3 get the Last ID from the Excel Table?

  • AgarDoge Profile Picture
    59 on at

    In the Update field,

     

    First(Sort(ExampleTable,ID, Descending)).ID + 1

     

     

    In the Default field,

     

    ThisItem.ID

     

     

     

  • AgarDoge Profile Picture
    59 on at

    I also tried changing the value of Update to DataCardValue3.Text  and the value of Default to First(Sort(ExampleTable1,ID, Descending)).ID+1 and I am getting the correct number of rows (in PowerApp) but when I open my Excel file only one row appears but then when i close the file and re-open it all of the multiples appear. But this switch still didn't update the ID # nor the Location for each record. 

  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @AgarDoge Try this,

    ForAll(
     ComboBox2.SelectedItems, //ComboBox2 contains list of locations that user can choose
     Patch(
     ExampleTable1,
     Defaults(ExampleTable1),
     {
     ID: DataCardValue3 + 1, //DataCardValue3 is where an ID is automatically added to ExampleTable1
     Location: ThisRecord.'Location Name'
     },
     Form3.Updates,
     )
    );
    Refresh(ExampleTable1);
    ResetForm(Form3)
  • AgarDoge Profile Picture
    59 on at

    I didn't make any difference, I still got the correct number of rows but nothing was updated - neither the ID nor the Location. Some more info about Location:

    Update: ComboBox2.Selected.'Location Name'

    Default: ThisItem.'Location'    //Location is the name of the column in the output table

     

    Updated code in OnSelect property of a "Submit" Button

     

    ForAll(
     ComboBox2.SelectedItems,
     Patch(
     ExampleTable1,
     Defaults(ExampleTable1),
     {
     ID: Value(DataCardValue3.Text) + 1,
     Location: ThisRecord.'Location Name'
     },
     Form3.Updates,
     )
    );
    Refresh(ExampleTable1);
    ResetForm(Form3)

     

     

  • Verified answer
    CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @AgarDoge The culprit in the code is  Form3.Updates

    This is overwriting the ID and the Location values we are trying to set. Just remove that and see if the ID and Location are getting patched as desired and later we can add the rest.

     

  • dyee Profile Picture
    145 on at

    Have you considered saving the data to a collection and doing a bulk submission?  It should be quite a bit faster.

  • AgarDoge Profile Picture
    59 on at

    That was the solution, I tried everything but never realized that was causing the issue. Thanks so much!

     

    I have a general question. In my code above, in the patch function I have {ID: .....} so if the name of the column was "ID Values" would it be better to write it as ID_x0020_Values: ____ or 'ID Values': _______ because they seem the same to me and look like they function the same

  • AgarDoge Profile Picture
    59 on at

    That is an interesting point, but I am not very familiar with ClearCollect()/Collect() (which I assume is what you are referring to for using in this situation) and manipulating/updating only a couple columns of the data. 

  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @AgarDoge Glad to help!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard