cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hong_yip
Helper III
Helper III

power apps Copy existing item and submit as new item on SharePoint

Hi,

 

We have created Canvas app user can submit new item to sharepoint list, is it any way user can get existing item and submit as new item on SharePoint?

2 ACCEPTED SOLUTIONS

Accepted Solutions
RusselThomas
Microsoft
Microsoft

Hi @hong_yip ,

You can use the Patch() function, but you probably want to strip out all the SPO auto-generated or system columns from the source record first - you can do this by using ShowColumns() or DropColumns(), depending which involves the least number of columns you want to specfy.  (ShowColumns if you have more you want to drop than show, DropColumns if you have more you want to show than drop).  

The first question is which row of data do you want to copy - so this needs to be from some sort of selection or lookup. 

ShowColumns() expects a table input, so instead of a lookup, we want to get our row into Table format. One way of doing this is using the Table() function - there's only one row in our result, but the data construct returned is a Table, so we can use ShowColumns() on it.  We then use First() on that to get back to a record construct.

For example, let's say you have "FirstName", "Surname" and "Email" columns in a SPO list. 

If you're displaying a gallery of all your SPO items, try adding a button to the page and set it's OnSelect: property to;

 

 

 

//Convert selected record into a table using Table() so we can then use ShowColumns() to strip everything that's unnecessary, then use First() to get back to a record
//Assumption is your Gallery Items: property is SPOList, otherwise instead of using Gallery.Selected, use a lookup on SPOList to find the correct record

With({ 
    copyRecord: First(ShowColumns(Table(Gallery.Selected), 
       "FirstName", 
       "Surname", 
       "Email"))
      },
    Patch(SPOList, Defaults(SPOList), copyRecord)
)

 

 

 

 Hope this helps,

RT

View solution in original post

WarrenBelz
Super User
Super User

Hi @hong_yip ,

Three ways I can think of - one set a Variable for the current record

Set(varRecord,ThisItem)

You would have to run this from inside a gallery or form for ThisItem to register.
Then a new form with each field Default set to the relevant field name

varRecord.YourFieldName

The others would be to set the same Variable and then use Patch

Patch(
   ListName,
   Defaults(ListName),
   {
      Field1:varRecord.Field1,
       . . . .  . . .
   }
)

You could also use Collect

With(
   {
      wItem:
      DropColumns(
         varRecord,
         "ID"
      )
   },
   Collect(
      YourListName,
      wItem
   )
)

 

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
RusselThomas
Microsoft
Microsoft

Hi @hong_yip ,

You can use the Patch() function, but you probably want to strip out all the SPO auto-generated or system columns from the source record first - you can do this by using ShowColumns() or DropColumns(), depending which involves the least number of columns you want to specfy.  (ShowColumns if you have more you want to drop than show, DropColumns if you have more you want to show than drop).  

The first question is which row of data do you want to copy - so this needs to be from some sort of selection or lookup. 

ShowColumns() expects a table input, so instead of a lookup, we want to get our row into Table format. One way of doing this is using the Table() function - there's only one row in our result, but the data construct returned is a Table, so we can use ShowColumns() on it.  We then use First() on that to get back to a record construct.

For example, let's say you have "FirstName", "Surname" and "Email" columns in a SPO list. 

If you're displaying a gallery of all your SPO items, try adding a button to the page and set it's OnSelect: property to;

 

 

 

//Convert selected record into a table using Table() so we can then use ShowColumns() to strip everything that's unnecessary, then use First() to get back to a record
//Assumption is your Gallery Items: property is SPOList, otherwise instead of using Gallery.Selected, use a lookup on SPOList to find the correct record

With({ 
    copyRecord: First(ShowColumns(Table(Gallery.Selected), 
       "FirstName", 
       "Surname", 
       "Email"))
      },
    Patch(SPOList, Defaults(SPOList), copyRecord)
)

 

 

 

 Hope this helps,

RT

View solution in original post

WarrenBelz
Super User
Super User

Hi @hong_yip ,

Three ways I can think of - one set a Variable for the current record

Set(varRecord,ThisItem)

You would have to run this from inside a gallery or form for ThisItem to register.
Then a new form with each field Default set to the relevant field name

varRecord.YourFieldName

The others would be to set the same Variable and then use Patch

Patch(
   ListName,
   Defaults(ListName),
   {
      Field1:varRecord.Field1,
       . . . .  . . .
   }
)

You could also use Collect

With(
   {
      wItem:
      DropColumns(
         varRecord,
         "ID"
      )
   },
   Collect(
      YourListName,
      wItem
   )
)

 

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

hong_yip
Helper III
Helper III

Thx WarrenBelz and RusselThomas reply 

i am explain not enough, a user may be need to getting existing item and modify item then submit as new item on SharePoint.is it possible?

Hi @hong_yip ,

Assuming you're using a gallery to 'select' the record you want to edit and duplicate, you can add an Edit form and set it's default mode to "New" and call it copyForm.

Then you would need to unlock and edit each of the cards in the form and set their "Default" property to the corresponding field in the record using Gallery.Selected.Fieldname 

Once you've done this for all the cards, this will allow the user to see the current values for the selected record, and they can change/edit any of the ones they could with an Edit form.

You can then add a button and set it's OnSelect: property to SubmitForm(copyForm) and it will create a new record.

Hope this helps,

RT  

@hong_yip ,

As per my post and I see there is also one from @RusselThomas , I gave you three options and Russel gave you a few more, so yes, it is possible using one of those methods.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,271)