cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jja
Post Partisan
Post Partisan

Patch insert new multiple selected records into dataverse table

Hi

I have a galery with checkboxes. I want to select multiple items and patch create records based on galery values and on additional textbox values into  specific dataverse table(not the table from where i get some info in galery)

these also include some lookup fields

What is the best approach of doing it?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@jja 

Please provide any formulas that you are trying and have errors and identify what is in error.

 

So then, I missed one word in your original post - "create"

You DO NOT want to update records that are checked in the Gallery, you want to create new records in another table.

If that is the case, then change the formula I provided to the following:

Patch(yourDataSource,
    ForAll(Filter(yourGallery.AllItems, yourCheckbox.Value),
        {
         column1: column1Value,
         etc
        }
    )
)

Or in other words...drop the primary key column!  If patch does NOT see a primary key in the records you provide it, then it will create them.  Be aware, you need to provide any required column values if you have any.  

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

19 REPLIES 19
RandyHayes
Super User
Super User

@jja 

Your formula would be similar to the following:

Patch(yourDataSource,
    ForAll(Filter(yourGallery.AllItems, yourCheckbox.Value),
        {ID: ID,
         column1: column1Value,
         etc
        }
    )
)
        

 

You need to provide the primary key!  In the above ID is used as the primary key (i.e. SharePoint), so for Dataverse, determine what your primary key is and replace the two ID's in the above.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Nogueira1306
Super User
Super User

I would recommend using a ForAll function...

 

Maybe, first create a collection for the itens for each table and after that do the patch

You check if the collection has data. If yes, ForAll() and Patch

If not, nothing.

 

ForAll - 
https://docs.microsoft.com/en-US/powerapps/maker/canvas-apps/functions/function-forall

 

Patch-

 

https://docs.microsoft.com/en-US/powerapps/maker/canvas-apps/functions/function-patch

 

 

If you need additional help please tag me in your reply and please like my reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️!

Best regards,
Gonçalo Nogueira

Check my LinkedIn!

Check my User Group (pt-PT)!

Last Post on Community

My website!

RandyHayes
Super User
Super User

@Nogueira1306 

No need to duplicate the data yet again in the app into a collection - the Gallery already contains all of the data needed.  Utilize the formula I provided to achieve the desired results.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

You are correct @RandyHayes . I thought that he wanted to create multiple data in defferent tables. 

Sorry @jja , just use ForAll() and Patch

RandyHayes
Super User
Super User

@Nogueira1306 

No worries - but even so, a collection is only needed when you need the ability to have an in-memory database with add/remove/edit capabilities.  For a Patch or ForAll or anything else that needs a table...well, all you need is a table!  AllItems is a Table 😁

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes  my only idea on the collections was for separate the tables, it would be easier (in my opinion), after that they would be deleted. Since it only needs 1 table, you are completily right, a collection would only complicate and maybr put the app slower

jja
Post Partisan
Post Partisan

Hi @RandyHayes in this table my primary name columns is Autonumber

How do i handle it in patch?

RandyHayes
Super User
Super User

@jja 

The Name of your column is Autonumber??  Or that is the type?

 

What you need to do is to look at your table definition in dataverse and verify what the primary key is - it will be annotated as the primary key.  THEN you need to replace the ID (both of them) in the formula with the actual name of the column.  And to be clear - it is the Column Name that you want to put int, NOT the Display name.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
jja
Post Partisan
Post Partisan

Hi @RandyHayes Automumber is a type

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PWREduCon768x460.png

Join us at PWR EduCon - A Power Platform Conference

Learn from the top Power BI, Power Apps, Power Automate & Power Virtual Agents experts!

Top Solution Authors
Top Kudoed Authors
Users online (2,594)