cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mnoah
Frequent Visitor

Use patch to duplicate a record dynamically

Hi all,

 

I want to use the Patch function to copy a sharepoint list record.  The list contains many columns (50+) so I do not want to write out each column name/value pair manually--I want it to get the values dynamically from a "RecordToCopy" record. I also do not want to use Power Automate for the same reason (in the Create Item connector I would have to indicate the value of each column).

 

2022-06-21 10_07_28-Power Apps — Mozilla Firefox.png

 

The above commands only result in a new liste item being created, with no values from the RecordToCopy copying over to NewRecord.

7 REPLIES 7
theapurva
Super User
Super User

Hello,
This is not working because when you are submitting the record, you are pushing read only columns also.
so you will have to drop the columns.

If you hover over your formula it will show the readonly fields which you are pushing so drop them and then Patch.

Below is Sample formula where I am dropping the read-only columns of my list.

Set(RecordToCopy,First(DropColumns(Filter(TeamDetails,ID=1),"ID","Modified")));
Set(NewRecord,Patch(TeamDetails,Defaults(TeamDetails)));
Patch(TeamDetails,NewRecord,RecordToCopy)

 

you can see the read only field causing the error by hovering over the formula:

theapurva_0-1655829237689.png

 

 

----------------------------------------------------------------------------------------------------------------------
Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!
mnoah
Frequent Visitor

@theapurvathank you.  This is a step in the right direction.  Looks like I will need to figure out all of the read-only fields.  So far I am up to "ID","Modified","{FullPath}", "{Identifier}"

mnoah
Frequent Visitor

@theapurvaI am stuck.  It is saying that "ResQuarterlyIntroID#Id" is read-only. But when I try to drop that column it says it does not exist.  "ResQuarterlyIntroID" I have dropped. (it is a lookup to another SP list).

 

Edit: it seems the lookup column is the issue.

 

 

2022-06-21 13_40_15-Power Apps — Mozilla Firefox.png

theapurva
Super User
Super User

hello @mnoah ,

Another workaround is like below:

Add a Gallery of that list then perform below

1. Add one Button say duplicate and edit and onselect of it redirect to editform

2. put edit form Item property as Gallery.Selected

3. Add a button named 'Save'.

4. Add below function to OnSelect of Save.

 

Patch(YourListName,Defaults(YourListName),YourEditForm.Updates)

 

This will create the new record in your list. 

this will save a lot of your effort I believe.

 


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!

 

 
----------------------------------------------------------------------------------------------------------------------
Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!
mnoah
Frequent Visitor

Hi @theapurva 

 

Thank you for the help.  But I am trying to do this "programmatically" and not with the help of an edit form.  I have 7 different SP lists.  They are all "connected" by an ID from a parent list.  User clicks a "Copy all records" button and I want a new record inserted into each list as a duplicate.  Perhaps a SP List was not the right tool for this job...

theapurva
Super User
Super User

Hello Could you confirm me about how are you looking UI?
If its like
there will be gallery and button 'Copy' on each record?

this button will copy item to other 7lists.

Is it like this?

----------------------------------------------------------------------------------------------------------------------
Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!
mnoah
Frequent Visitor

No, I am only using a gallery for parent list (which just contains meta-data).  The main screen allows user to choose a parent record, and then I have 7 different screens with EditForms that all pull in data from the parent record.

 

I think what I am going to have to do is have one screen with all of the edit forms, and a "Copy records" button that loops through each section and patches with the form.updates method.

 

2022-06-21 15_57_47-.png

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (4,329)