cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HarishNayak
Helper II
Helper II

Efficient way to create new items in a sharepoint list from a collection

Hi All,

 

I have created a power app and my requirement is as mentioned below

 

When a new item is created in List 1, i need to create 10 pre defined items in List 2. Also List 2 has a ParentID column which should refer to the ID from List 1 when an new is item created.

 

Trying to understand the most efficient way for doing this.

 

What i am doing now is,

  1. When my power apps loads i have a collection which has the 10 pre defined items .
  2. Created a new Item form
  3. On success of when a new item is created i am using UpdateIf to update one of the collection column to the ID of the newly created item
  4. Then using Patch( sharepoint list name, Collection Name), the 10 pre defined items get created in List 2.
  5. It takes about 5 seconds for this operation to complete

This seems to work but in the Patch documentation it says to use Defaults() to create new item. So i am unsure if this is the right way of doing it or if there is a better and efficient way.

 

Any inputs will be helpful

1 ACCEPTED SOLUTION

Accepted Solutions

@HarishNayak ,

I generally only use UpdateIf() when I want to update multiple matching items (Patch otherwise), but it certainly works on a single item. Collect works for updating both a collection and (when the fields align) a list as does Patch (your code) on a list in the same scenario. 

Having said this, what you use is at times a personal preference if both options work effectively. As most of my apps are used in the field and all data succeeding to write is far more important than a few milliseconds in performance, I use Patch() a lot.

 

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.

View solution in original post

5 REPLIES 5
WarrenBelz
Super User
Super User

Hi @HarishNayak ,

You did not supply any code, but to answer your question Patch using Defaults(ListName) as the parameter is the correct way of creating new records in a list.

If all the fields in the collection are contained in name and data type in the List, you can also use

Collect(
   ListName,
   CollectionName
)

 

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 

 

thanks for checking this. May be i should have explained better.

 

I have 2 sharepoint Lists, List 1 & List 2.
I have another list named Documents which has 10 items ( these are my pre defined items what i want to be copied each time to List 2 when an item is created in List 1)

 

I have created an app to create item for List 1

OnStart 

ClearCollect(colDocument,ShowColumns(Filter('Documents',DocType ="Account"),"DocName","ParentID"))

 

Form 1 is to create item in List 1


OnSuccess of Form1
UpdateIf(colDocument,true,{ParentID: Form1.LastSubmit.ID});
Patch('List2',colAccountDoc)

 

Like i said this created new entries in List 2 without using the Defaults()

Hi @HarishNayak ,

There are many ways of achieving the same result in Power Apps. Your Patch code should work if all the fields from the collection line up with the List (Collect does as well), but I have found the Patch syntax buggy in the past and stick with what I know always works. Your UpdateIf code is also interesting as you would normally use Collect() for what you are doing.

 

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 , are you suggesting to just use Collect(). If yes was wondering how could i update the ParentID column. I would still need to use the updateif function

 

I tried Updateif and Collect(). It works but sower when compared to Updateif and Patch()

@HarishNayak ,

I generally only use UpdateIf() when I want to update multiple matching items (Patch otherwise), but it certainly works on a single item. Collect works for updating both a collection and (when the fields align) a list as does Patch (your code) on a list in the same scenario. 

Having said this, what you use is at times a personal preference if both options work effectively. As most of my apps are used in the field and all data succeeding to write is far more important than a few milliseconds in performance, I use Patch() a lot.

 

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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (3,416)