
Announcements
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?
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