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

Copying Attachments from an existing Sharepoint List Item to new item

Hi,

 

I created a custom Sharepoint Form, which should have the feature, to fill all fields with the values from an existing item. After that the user should be able to make some changes to the values and submit the form. At the moment everything works fine except the copying of attachments.

This is the fomula for "items" of the Attachments card:

If(gblLoadItem, LookUp(SPOList, ID=locLoadExistingItem.ID).Attachments, Parent.Default)

 This works to display the attachments in the Form if "gblLoadItem" is set to true.

MatthiasG_0-1608632605308.png

I'm also able to add more attachments manually. After submitting only the manually added attachments are saved for the new item. I already tried to change the "Value" of the attachments control to Id, Value and AbsoluteUri which obviously didn't help.
My guess for the problem is, how powerapps and the attachments control handle the files.
Is there any approach which could solve my problem?

 

Thanks in advance,

Matthias 

1 ACCEPTED SOLUTION

Accepted Solutions
MatthiasG
Frequent Visitor

I tried to come up with a solution for this today and I want to share it in case that someone finds this thread and has a similar problem:
The goal was as i described above, to copy an existing item  with its attachmants into a Form, make some changes (including the attachments) and then save as new list item.
First of all I created a flow, which takes following JSON as Input and is triggered by PowerApps:

 

 

{
  "oldId": 1,
  "newId": 2,
  "attachments": [
    {
      "id": "FILE_IDENTIFIER1",
      "name": "example.png"
    },
    {
      "id": "FILE_IDENTIFIER2",
      "name": "example2.png"
    }
}

 

 

 

MatthiasG_0-1608726878565.png

The flow has to parse the JSON Input and then iterate over eacht attachment. In the loop first the content of the current attachment has to be retrieved and then save to the new item.

For the PowerApp I kept everything the same as explained in the initial post.



I only had to add some stuff to the saving process. In "onSave" of the SharepointIntegration I changed it to the following (atsAttachments is the Attachments controle):

 

 

If(gblLoadItem, 
ClearCollect(colAdditionalAts, 
  RenameColumns(
    Filter(atsAttachments.Attachments, ThisRecord.Value in LookUp(SPOList, 
    ID=gblLoadExistingItem.ID).Attachments.Id), 
  "Value", "id", "Name", "name")));
SubmitForm(frmEdit)

 

 

 In "onSuccess" you can get the ID of the last submitted item, which we need for the flow. This changes the "onSuccess" formula to the following:

 

 

If(gblLoadItem,
ExampleFlow.Run(JSON({oldId: gblLoadExistingItem.ID, newId: Self.LastSubmit.ID, attachments: colAdditionalAts})));
ResetForm(frmEdit); Set(gblLoadAufgabe, false); RequestHide();

 

 

 

That's all I had to do.

View solution in original post

4 REPLIES 4
Reimi
Community Support
Community Support

You can't copy attachments via attachment control.

You can use flow instead.

MatthiasG
Frequent Visitor

OK thanks for the fast reply. I guess I have to come up with something complicated to fulfill my requirements then.

MatthiasG
Frequent Visitor

I tried to come up with a solution for this today and I want to share it in case that someone finds this thread and has a similar problem:
The goal was as i described above, to copy an existing item  with its attachmants into a Form, make some changes (including the attachments) and then save as new list item.
First of all I created a flow, which takes following JSON as Input and is triggered by PowerApps:

 

 

{
  "oldId": 1,
  "newId": 2,
  "attachments": [
    {
      "id": "FILE_IDENTIFIER1",
      "name": "example.png"
    },
    {
      "id": "FILE_IDENTIFIER2",
      "name": "example2.png"
    }
}

 

 

 

MatthiasG_0-1608726878565.png

The flow has to parse the JSON Input and then iterate over eacht attachment. In the loop first the content of the current attachment has to be retrieved and then save to the new item.

For the PowerApp I kept everything the same as explained in the initial post.



I only had to add some stuff to the saving process. In "onSave" of the SharepointIntegration I changed it to the following (atsAttachments is the Attachments controle):

 

 

If(gblLoadItem, 
ClearCollect(colAdditionalAts, 
  RenameColumns(
    Filter(atsAttachments.Attachments, ThisRecord.Value in LookUp(SPOList, 
    ID=gblLoadExistingItem.ID).Attachments.Id), 
  "Value", "id", "Name", "name")));
SubmitForm(frmEdit)

 

 

 In "onSuccess" you can get the ID of the last submitted item, which we need for the flow. This changes the "onSuccess" formula to the following:

 

 

If(gblLoadItem,
ExampleFlow.Run(JSON({oldId: gblLoadExistingItem.ID, newId: Self.LastSubmit.ID, attachments: colAdditionalAts})));
ResetForm(frmEdit); Set(gblLoadAufgabe, false); RequestHide();

 

 

 

That's all I had to do.

 

MatthiasG
Frequent Visitor

I tried to come up with a solution for this today and I want to share it in case that someone finds this thread and has a similar problem:
The goal was as i described above, to copy an existing item  with its attachmants into a Form, make some changes (including the attachments) and then save as new list item.
First of all I created a flow, which takes following JSON as Input and is triggered by PowerApps:

 

 

{
  "oldId": 1,
  "newId": 2,
  "attachments": [
    {
      "id": "FILE_IDENTIFIER1",
      "name": "example.png"
    },
    {
      "id": "FILE_IDENTIFIER2",
      "name": "example2.png"
    }
}

 

 

 

MatthiasG_0-1608726878565.png

The flow has to parse the JSON Input and then iterate over eacht attachment. In the loop first the content of the current attachment has to be retrieved and then save to the new item.

For the PowerApp I kept everything the same as explained in the initial post.



I only had to add some stuff to the saving process. In "onSave" of the SharepointIntegration I changed it to the following (atsAttachments is the Attachments controle):

 

 

If(gblLoadItem, 
ClearCollect(colAdditionalAts, 
  RenameColumns(
    Filter(atsAttachments.Attachments, ThisRecord.Value in LookUp(SPOList, 
    ID=gblLoadExistingItem.ID).Attachments.Id), 
  "Value", "id", "Name", "name")));
SubmitForm(frmEdit)

 

 

 In "onSuccess" you can get the ID of the last submitted item, which we need for the flow. This changes the "onSuccess" formula to the following:

 

 

If(gblLoadItem,
ExampleFlow.Run(JSON({oldId: gblLoadExistingItem.ID, newId: Self.LastSubmit.ID, attachments: colAdditionalAts})));
ResetForm(frmEdit); Set(gblLoadAufgabe, false); RequestHide();

 

 

 

That's all I had to do.

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,290)