cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bri
Level: Powered On

Patch multiple records

I need to patch or insert certain fields for every record in a collection, into a datasource. Meaning, FOR all records in my collection, insert an individual record with certain fields into some datasource.

 

Her is my collection: coll.FieldA, coll.FieldB, coll.FieldC

 

I need to do a ForAll(coll, patch(DATASOURCE, {datasource.fieldA: coll.FieldA, datasource.fieldB: coll.fieldB}))

 

HOW can this be done? CAN it be done?!?!?

5 REPLIES 5
Bri
Level: Powered On

Re: Patch multiple records

Heres what i am trying to get to work. Basicall I concat a string of a bunch of records, and then use collect to add it all to a datasource... kinda silly

 

UpdateContext(recordsToSubmit: Concat(coll, "{Datasource.FieldA: " & FieldA & ", Datasource.FieldB: " & FieldB "}, ")}); UpdateContext({recordsToSubmit: Left(recordsToSubmit, (Len(recordsToSubmit) - 2))}); collect(Datasource, recordsToSubmit)

 

What this does, is it makes recordsToSubmit a string that looks like, "{datasource.fieldA: fieldA, Datasource.FieldB: fieldB}, {datasource.fieldA: fieldA, Datasource.FieldB: fieldB}, {datasource.fieldA: fieldA, Datasource.FieldB: fieldB}" for how ever many records you have, but when you pass a variable as the "records" to the collect function, it does not run.... HELP

Microsoft Employee

Re: Patch multiple records

This might help you:

ForAll(Records, Collect(NewRecords, Concatenate("{Datasource.FieldA:",FieldA,"Datasource.FieldB:",FieldB,"}") ))
Community Support Team
Community Support Team

Re: Patch multiple records

Hi @Bri,

 

Use forall and the patch function should work.

But in order to distinguish column name between collection and datasource, here we would use renamecolumns function to rename the column name in collection.

Please take a look at the following example:

patch multiple records which include lookup field

In your scenario, we should also take use of the renamecolumns function three times (depends on the field you would like to patch with):

ForAll(
   RenameColumns(
      RenameColumns(
               RenameColumns(Collection,"FieldA","FieldA1"),
                   "FieldB","FieldB1"),
                  "FieldC","FieldC1"),
   Patch(Datasource,
         Defaults(Datasource),
         {FieldA: FieldA1,FieldB:FieldB1,FieldC: FieldC1}
        )
  )

The formula above would add new records for each records in the collection.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PierreGiusti
Level: Powered On

Re: Patch multiple records

Hi, when I utilize a collection where don’t have group this formula works, but in my case, I have a collection where one field is a group, so when I try to add records in database, the system show an error message some like that “the field X was waiting an number type. Type found is Table”.

 

For example, to show this collection in a gallery I have this command:

 

Ungroup( Cl_CalendActivid;"IDActividad")

 

So I try to replace collection by Ungroup command, but also didn’t work:

 

ForAll(

   RenameColumns(

     RenameColumns(

               RenameColumns(Ungroup( Cl_CalendActivid;"IDActividad"),"FieldA","FieldA1"),

                   "FieldB","FieldB1"),

                 "FieldC","FieldC1"),

   Patch(Datasource,

         Defaults(Datasource),

         {FieldA: FieldA1,FieldB:FieldB1,FieldC: FieldC1}

       )

)

 

Could you help with this issue?

 

PS: It’s possible create a collection ungrouped? The command that I utilize is (where have N lines at Gallery_CalendActvAbiert.AllItems to one line in IDCalendario):

 

ClearCollect('Cl_CalendActivid';

{IDCalendario: 1;

 IDActividad:  ShowColumns(Filter(Gallery_CalendActvAbiert.AllItems;Checkbox1.Value = true);"IDActividad")}

)

 

Thanks in advance.

 

Pierre

Goodwill
Level: Powered On

Re: Patch multiple records

Hi am creating an app where i have set password page, i want a user to be able to set there own password and get the flexibility to update it from the datasourse using the power app

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 202 members 4,517 guests
Please welcome our newest community members: