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 / 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

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
Kalathiya Profile Picture

Kalathiya 421

#2
WarrenBelz Profile Picture

WarrenBelz 365 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 339 Super User 2025 Season 2

Last 30 days Overall leaderboard