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 / Change attachment file...
Power Apps
Answered

Change attachment file name almost working

(0) ShareShare
ReportReport
Posted on by

Hello everyone,

 

I'm trying to change the file name of an attachment in an attachment control. So far, I've followed a solution from this thread.

I used this script in the OnAddFile of the Attachment DataCardValue control. Then used colAttachments in the Items property of the same control and colAttachments in the Update property of the Attachment datacard control. However, something weird seems to be happening...

1. On adding the attachment file with colAttachments in the Items property and Update property, the file does not attach. 

2. If I remove colAttachments from either Items property or Update property, I'm able to attach the file but it shows the original file name. While the file is attached, if I change either the Items property or Update property, so that both properties have colAttachments, then the file name changes to the new name.

 

ClearCollect(
 colAttachments,
 {
 AbsoluteUri: " ",
 DisplayName: " ",
 Id: " ",
 Name: " ",
 Value: " "
 }
);
Collect(
 colAttachments,
 DataCardValue16.Attachments
);
RemoveIf(
 colAttachments,
 Id = " "
);
UpdateIf(
 colAttachments,
 Len(First(colAttachments).Name) >= 1,
 {
 Name: Replace(
 First(colAttachments).Name,
 1,
 (Len(First(colAttachments).Name) - 4),
 "invoice" & Text(
 Now(),
 "[$-en-US]yyyy-mm-dd-hh-mm-ss"
 )
 ),
 DisplayName: Replace(
 First(colAttachments).Name,
 1,
 (Len(First(colAttachments).Name) - 4),
 "invoice" & Text(
 Now(),
 "[$-en-US]yyyy-mm-dd-hh-mm-ss"
 )
 )
 }
)

 

 Is there any way I can resolve this problem?

Categories:
I have the same question (0)
  • Verified answer
    AdaEloka Profile Picture
    on at

     

    I was finally able to figure it out!

    I used the form from modern controls...just in case...

    In the OnAddFile of the attachment control, use

     

    //Change the Update property of the attachment data card so attached files can be added and their name changed.
    UpdateContext({varDelete: colAttachments});
    Clear(colAttachments);
    ClearCollect(
     colAttachments,
     {
     AbsoluteUri: " ",
     DisplayName: " ",
     Id: " ",
     Name: " ",
     Value: " "
     }
    );
    Collect(
     colAttachments,
     DataCardValue31.Attachments
    );
    RemoveIf(
     colAttachments,
     Id = " "
    );
    ForAll(
     DataCardValue31.Attachments,
     UpdateIf(
     colAttachments,
     !("invoice-" in Name),
     {
     Name: "invoice-" & Text(
     Now(),
     "yyyymmddhhmmss"
     ) & Right(
     Name,
     5
     ),
     DisplayName: "invoice-" & Text(
     Now(),
     "yyyymmddhhmmss"
     ) & Right(
     Name,
     5
     )
     }
     )
    );

     

     

    In the Items property of the attachment control, use Parent.Default

    In the OnRemoveFile of the attachment control, use UpdateContext({varDelete: DataCardValue31.Attachments})

    In the Update property of the attachment data card, use varDelete

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 531 Most Valuable Professional

#2
Haque Profile Picture

Haque 261

#3
Kalathiya Profile Picture

Kalathiya 221 Super User 2026 Season 1

Last 30 days Overall leaderboard