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,
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
Solved! Go to Solution.
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.
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()
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.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
185 | |
53 | |
41 | |
36 | |
30 |
User | Count |
---|---|
242 | |
81 | |
71 | |
69 | |
65 |