cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bri
Advocate II
Advocate II

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
Advocate II
Advocate II

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

This might help you:

ForAll(Records, Collect(NewRecords, Concatenate("{Datasource.FieldA:",FieldA,"Datasource.FieldB:",FieldB,"}") ))
v-micsh-msft
Community Support
Community Support

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.

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

Anonymous
Not applicable

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (43,322)