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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Multiple Attachment Co...
Power Apps
Unanswered

Multiple Attachment Controls (Renaming Files)

(0) ShareShare
ReportReport
Posted on by

Hello everybody,

 

My EditForm contains multiple attachment controls. For future reference, I'd like to change the name of the file based on the attachment control that was used to add the attach the file.

 

I found this excellent video from Reza Dorrani: https://www.youtube.com/watch?v=hJQjGE-oUpM

 

From 14:24 he shows that what I want to do is achievable, but I'm simply not good enough to see how he has done this.

 

For the attachment control where the user attaches a shipping label, I've tried the following OnAddFile properties:

1)

{Name:"ShipLabel-" & ThisItem.Name,
DisplayName: "ShipLabel-" & ThisItem.Name}

2)

{Name:"ShipLabel-" & Name,
DisplayName: "ShipLabel-" & }

 

Option1 does not do anything, and option2 fails because 'Name' is not recognized.

 

I'm hoping that someone can steer me into the right correction with this issue and would truly appreciate your input.

Categories:
I have the same question (0)
  • gcmfaizan Profile Picture
    1,022 on at

     

    Hi @Anonymous ,

     

    Assuming you have multiple attachment controls in your EditForm, each representing a different type of attachment (like shipping label, receipt, etc.), you can differentiate them by adding a unique identifier to the file name. Here's a step-by-step approach:

     

    Set the OnAddFile Property: For each attachment control, you can set the OnAddFile property to update the name of the file being added. You can use the Defaults function to get the default properties of the record and then modify the Name property.

     

     

     

    OnAddFile:
    Collect(
     AttachmentCollection,
     {
     Name: "ShipLabel-" & ThisItem.Name, // Modify based on your requirement
     DisplayName: "ShipLabel-" & ThisItem.Name,
     Content: DataUriToBinary(DataUri)
     }
    )

     

     

    Replace "ShipLabel-" with any prefix you want to use for the file names. You can customize the file naming convention as needed.

    Also, make sure that AttachmentCollection is a collection that you've defined earlier in your app.

    Please accept my post as solution to help others as well. 

    Cheers!

     

  • Community Power Platform Member Profile Picture
    on at

    Hey @gcmfaizan 

     

    Thanks for your response!!

     

    I'm defining a collection in the onstart property of my app:

    ClearCollect(
     AttachmentCollection,
     [
     "ShipLabel-",
     "PreAdv-",
     "Docs-"
     ]
    )

     

    This collection represents the three attachment types/controls and I'd like my attachments to start with this 'prefix'. 

     

    I set the OnAddFile to the following code:

    Collect(
     AttachmentCollection,
     {
     Name: "ShipLabel-" & ThisItem.Name,
     DisplayName: "ShipLabel-" & ThisItem.Name,
     Content: DataUriToBinary(DataUri)
     }
    )

     

    This part of the code: 'Content: DataUriToBinary(DataUri)' has two errors. 1 DataUriToBinary is an unknown or unsupported function. 2Name isn't valid. DataUri isnt recognized.

    I'm not sure what that portion of the code is supposed to do, but removing it results in no errors, but when I upload a file, the name is not changed. 😞

     

    What am I missing?

  • gcmfaizan Profile Picture
    1,022 on at

    Hi @Anonymous ,

     

    I see you already define AttachmentCollection OnStart, now For each attachment control (e.g., AttachmentControlShippingLabel), set the OnAddFile property as follows:

     

     

     

     

     

    Collect(
     AttachmentFiles,
     {
     Name: LookUp(AttachmentCollection, Value = "ShipLabel-") & ThisItem.Name,
     DisplayName: LookUp(AttachmentCollection, Value = "ShipLabel-") & ThisItem.Name,
     ContentBytes: ThisItem
     }
    )

     

     

     

     

     

    Submitting the Form:

    When you submit the form, make sure you include the AttachmentFiles collection in the Patch function, assuming your data source has an attachments field.

     

     

     

     

    Patch(
     YourDataSource,
     YourEditForm.Updates,
     {
     Attachments: AttachmentFiles
     }
    )

     

     

     

     

    By using LookUp to retrieve the prefix and concatenating it with the file name, you can achieve the desired attachment naming. Also, make sure to handle clearing the AttachmentFiles collection after submitting the form to avoid conflicts with subsequent submissions.

     

     

    I hope now it works for you and please accept post my solution to help the community.

     

    Thanks!

  • Community Power Platform Member Profile Picture
    on at

    Hi @gcmfaizan 

     

    Thanks for your help again. Unfortunately, the LookUp kept generating an 'Invalid Argument' error. After some back and forth, I adjusted the code to make the invalid argument error disappear. With my updated code there are no errors anymore, but when I upload a file, the name is not adjusted at all. Can you tell what is wrong? I did let my OnStart property run. Here is the code:

    OnStart: ClearCollect(
     AttachmentCollection,
     [
     { AttachmentControl: "ShipLabel", Prefix: "ShipLabel-" },
     { AttachmentControl: "PreAdv", Prefix: "PreAdv-" },
     { AttachmentControl: "Docs", Prefix: "Docs-" }
     ]
    )

     

    OnAddFile: Collect(
     AttachmentFiles,
     {
     Name: LookUp(AttachmentCollection, AttachmentControl = "ShipLabel").Prefix & ThisItem.Name,
     DisplayName: LookUp(AttachmentCollection, AttachmentControl = "ShipLabel").Prefix & ThisItem.Name,
     ContentBytes: ThisItem
     }
    )
  • gcmfaizan Profile Picture
    1,022 on at

    Hi  @Anonymous , 

     

    If you want to dynamically select the prefix based on the attachment control, you should update the OnAddFile formula like this:

     

     

     

    Collect( AttachmentFiles, { Name: LookUp(AttachmentCollection, AttachmentControl = "ShipLabel").Prefix & ThisItem.Name, DisplayName: LookUp(AttachmentCollection, AttachmentControl = "ShipLabel").Prefix & ThisItem.Name, ContentBytes: ThisItem } )

     

     

    Replace "ShipLabel" with the appropriate attachment control name where this code is being executed. For example, if you're attaching a file from the "PreAdv" attachment control, you should use:

     

     

     

    Collect( AttachmentFiles, { Name: LookUp(AttachmentCollection, AttachmentControl = "PreAdv").Prefix & ThisItem.Name, DisplayName: LookUp(AttachmentCollection, AttachmentControl = "PreAdv").Prefix & ThisItem.Name, ContentBytes: ThisItem } )

     

     

    This way, you'll be using the correct prefix based on the attachment control, and the file names should adjust as expected.

     

    I hope now may it's work.

  • Community Power Platform Member Profile Picture
    on at

    Hi @gcmfaizan,

     

    I've tried your code but unfortunately it doesn't do anything when I upload a file. The code doesn't generate any errors, so I can't tell why it isn't doing anything. I have no clue what could be wrong, so unfortunately I'm going to work around this. Thanks for your help though.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard