web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patching Attachments o...
Power Apps
Answered

Patching Attachments on Submit OnSelect property without form update

(0) ShareShare
ReportReport
Posted on by 25
I have a form with Submit button using a patch so I can create new records based on how many agencies are selected. The form has an attachment field from the SharePoint list. I need what attachment(s) to be added to every row that creates a new record. I have the right records being created so I just need to get the attachment(s) on every record. I have tried multiple different ways and nothing I am doing is working. I have great luck in the forum so I figured I would try again.
 
// 1. Collect records and safely handle Blank Agencies
ClearCollect(
    colIRRecords,
    ForAll(
        If(
            IsBlank(valAgencies.SelectedItems), 
            [ { Value: Blank() } ], // Fallback if multi-select is empty
            valAgencies.SelectedItems
        ) As SelectedAgency,
        {
            Title: Coalesce(SelectedAgency.Value, "NoAgency") & " " &
                   Substitute(
                        Substitute(
                            Substitute(
                                Substitute(
                                    Substitute(
                                        Substitute(
                                            Substitute(
                                                Substitute(
                                                    Substitute(
                                                        Substitute(
                                                            Substitute(
                                                                Substitute(
                                                                    Substitute(
                                                                        Substitute(valShortDesc.Text, " ", ""),
                                                                        " ", ""
                                                                    ), 
                                                                    "@", ""
                                                                ), 
                                                                "#", ""
                                                            ), 
                                                            "$", ""
                                                        ), 
                                                        "|", ""
                                                    ), 
                                                    ":", ""
                                                ), 
                                                "\\", "" /* Corrected backslash escape */
                                            ), 
                                            "/", ""
                                        ), 
                                        "[", ""
                                    ), 
                                    "]", ""
                                ), 
                                ",", ""
                            ), 
                            "'", ""
                        ), 
                        Char(34), "" /* For double quotes (") */
                    ),
            DtOfInc: Today(),
            DateDetected: valDtDetected.SelectedDate,
            CaseNum: valCaseNum.Text,
            Status: If(!IsBlank(valStatus.Selected), {Value: valStatus.Selected.Value}, Blank())            
            // I have more fields but removed them for this forum
        }
    )
);
// 2. Patch Collection to Data Source, safely handling blank attachments
ForAll(
    colIRRecords As NewRec,
    Patch(
        MyList,
        Defaults(MyList),
        NewRec
    )
);
// 3. Success Notification
Notify("Incident submitted successfully!", NotificationType.Success, 3000);
// 4. Clear the form data and revert to default values
ResetForm(frmNYSOCIntake);
// 5. Optional: Set the form back into "New" mode if creating subsequent entries
NewForm(frmMyForm);
Categories:
I have the same question (0)
  • Suggested answer
    11manish Profile Picture
    3,333 on at
    Since you're creating multiple SharePoint items from a single form submission, the best practice is to:
    • Continue using Patch() to create each list item.
    • Capture the IDs of the newly created items.
    • Call a Power Automate flow to copy the uploaded attachment(s) to each new item using the SharePoint Get attachment content and Add attachment actions.
    This approach is the most robust, fully supported, and scales well if users upload multiple files.
  • Verified answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at

    You could handle this by using Power Automate and Patch code.

    First, Implement your Patch() code and store the response in a collection. 

    Then, loop through the collection of patched records (So you have created records ID). For each record, loop through the attachments collection and call a Power Automate flow. Pass the SharePoint item ID from the outer loop along with the attachment name and file content from the inner loop. The flow can then upload each attachment to the corresponding SharePoint item.

    Please refer to the sample code below, which shows how to patch multiple SharePoint items along with their attachments.

    Power Automate - Steps

    #1. Add a Power Apps (V2) trigger and create 2 input parameters:
    - ID (Number)
    - File (File)
    #2. Add the SharePoint - Add attachment action. Select your SharePoint Site and List. For ID, use the ID parameter from the trigger. For File Content, use the File Content from the trigger. For File Name, use this expression:

    Reference link: 
    How to upload attachment using Power Automate: 

    https://medium.com/@ittichai/power-apps-with-attachment-control-to-send-file-content-to-power-automate-32c67f1668b7

     

    ---------------------------------------------------------------------------
    Glad it helped 🙂
    If this fixed your issue,
    please click “Does this answer your question?” to mark it as verified so others can find the solution easily.
    A Like 👍 is always appreciated, and I’m around if you need more help @Kalathiya
  • Suggested answer
    WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Please refer to this blog of mine - it is designed for offline attachments, however just skip that bit and have a look at how to add attachment content to a Collection, then how to update your SharePoint List with the collection, including attachments.
     
    Please Does this answer your question 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 answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • DB-22041341-0 Profile Picture
    25 on at
    Thanks All -- I really don't want to use a flow if I don't have to. I don't understand why I can't patch the attachments at same time as the rest of the fields. I have tried 
    Attachments: Table( Name: ThisRecord.Name, Value: ThisRecord.Value})
    and 
    Table(valAttach As AttachedDocs, {DisplayName: AttachedDocs.DisplayName, AbsoluteURI: Blank(), Id: AttachedDocs.Id, Value: AttachedDocs.Value})
    and even doing a new collection
    ClearCollect(colAttachments, ForAll(valAttach.Attachments, {DisplayName: valAttach.Name, Value: valAttach.Value}))
     
    Nothing works.
     
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Please have a read of the blog I posted - I have an example of this working in a prod app. You need the hidden gallery with Image and Label controls to convert the BLOB reference to actual file content. You also need to collect the rest of the record with the Attachments if there are other fields (to keep them on the same record)
    Collect(
       colYourCol,
       {
          YourField1: YourContro11Output,
          YourField2: YourContro12Output,
          . . . . . .
          Attachments: 
          Table(
             ForAll(
                galAttachments.AllItems As _Files,
                {
                   DisplayName: _Files.lblAttachName.Text,
                   AbsoluteUri: Blank(),
                   Id: _Files.imgAttachContent.Image,
                   Value: _Files.imgAttachContent.Image
                }
             )
          )
       }
    );
    then patching the Collection back
    ForAll(
       colYourCol As _Data,
       {
          YourField1: _Data.YourField1,
          YourField2: _Data.YourField2,
          . . . . . . .
          Attachments: 
             Table(
                ForAll(
                   _Data.Attachments As _Files,
                   {
                      DisplayName: _Files.DisplayName,
                      AbsoluteUri: Blank(),
                      Id: _Files.Id,
                      Value: _Files.Value
                   }
                )
             )
          }
       )
    )
     
    Please Does this answer your question 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 answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard