Introduction:
Resolution:
Below are the steps we are going to work on here!
1. Set restriction on uploading other extension files in Attachment
control
and notify the user when they upload any extension file other than ".pdf".
2. Restrict the user from saving until resolving file errors.
Step 1: Set restriction on uploading other extension files in Attachment control
Place the below code at OnAddFile property of the
Attachment control:
If(
CountRows(
Filter(
RenameColumns(
DataCardValue4.Attachments,
"Name",
"NewName"
),
Last(
Split(
NewName,
"."
)
).Result <> "pdf"
)
) > 0,
Notify(
"Only PDF files can be attached",
NotificationType.Error
);
,
SubmitForm(Form1);
ResetForm(Form1);
EditForm(Form1);
)
After placing this, check by adding a different extension file in the attachment control. You will be able to see this type of error at the top of the app.
Now as we have set the restriction message, let’s restrict the user from saving the form until all the attachments in the control are ".pdf".
Step2: Restrict user from saving until resolving file errors
Place the below code in the OnSelect property of the save
button or in the OnSave property of
SharePointIntegration:
If(
CountRows(
Filter(
RenameColumns(
DataCardValue4.Attachments,
"Name",
"NewName"
),
Last(
Split(
NewName,
"."
)
).Result <> "pdf"
)
) > 0,
Notify(
"Only PDF files can be attached",
NotificationType.Error
);
,
SubmitForm(Form1);
ResetForm(Form1);
EditForm(Form1);
)
Now add a different file extension in the control and click on save. It will show the below error and won’t let the user save the item.
Conclusion
This is how we can restrict users to upload only ".pdf" extension files in the Power Apps - Form Attachment Control.
No comments:
Post a Comment