I'm trying to change the file name of an attachment in an attachment control. So far, I've followed a solution from online 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 data card control. However, something weird seems to be happening.
On adding the attachment file with
colAttachmentsin theItemsproperty andUpdateproperty, the file does not attach.If I remove
colAttachmentsfrom eitherItemsproperty orUpdateproperty, I'm able to attach the file but it shows the original file name. While the file is attached, if I change either theItemsproperty orUpdateproperty, so that both properties havecolAttachments, 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?
The script provided in the thread seems to be causing issues with attaching the file and changing the file name in the attachment control. One possible solution is to use the Patch function instead of the Collect and UpdateIf functions. Here's an example script that uses the Patch function to update the file name:
This script first collects the attachments in the attachment control and removes any empty attachments. Then, it uses the Patch function to update the file name and display name of the first attachment in the collection. The file name is set to "invoice" followed by the current date and time in the format "yyyy-mm-dd-hh-mm-ss" and the file extension ".pdf". The display name is set to the same value as the file name.