Display Form Canvas App See Last Record Submission [Building Power Apps In Microsoft Teams – Ep. 5]
Safeguard Deleting Attachments In Canvas Apps
At Pragmatic Works, we frequently encounter challenges that are unique to our users' needs. In this week's video, Matt Peterson, a trainer at Pragmatic Works, tackled an issue raised by a client during a virtual mentoring session. The client wanted users to be able to edit records and add attachments in a Canvas App, but without the ability to delete them. This tutorial demonstrates the steps to address this need effectively using Canvas App logic.
The Challenge
The client’s requirement was clear: users should be allowed to edit records, add attachments, but not delete them. In Canvas Apps, the attachment control includes a delete icon by default, but unfortunately, there is no out-of-the-box solution to simply hide or remove the delete icon. This meant Matt had to get creative to ensure that users could not remove attachments once they were added.
Initial Idea: Removing the Delete Icon
Initially, Matt considered removing the delete icon by simply hiding it, but after some exploration, he realized that Canvas Apps doesn’t allow for hiding the delete button directly through properties. So, he had to find another solution.
The First Attempt: Single File Attachments
The first solution Matt came up with worked well when there was only one file allowed in the attachment. Using a variable, he could track whether the user had deleted a file or not and disable the save button accordingly. However, this approach only worked when there was a single attachment per record. Since the requirement was for multiple attachments, Matt had to revise his approach.
The Final Solution: Multi-file Attachments and Variables
Matt’s final solution uses global variables to track changes in the record and control the functionality of the save button.
Step-by-Step Breakdown:
- Variable Initialization: Matt started by setting a global variable,
VAR_disable_save, to control whether the save button is enabled or disabled. - Tracking File Deletions: Matt configured the app to track when a user attempts to delete a file by increasing the value of the variable. This triggers a notification that tells the user they cannot save the record.
- Disabling the Save Button: Using conditional logic, Matt disabled the save button if the variable value indicated that a file had been deleted. This prevented the user from saving changes when attachments were removed.
- Handling Undo: Matt also included logic for undoing the file deletion. When the user undoes the deletion, the variable is adjusted accordingly, allowing the save button to be re-enabled.
- Resetting the Variable: To ensure the functionality worked across different records, Matt added logic to reset the variable when switching between records in the gallery, ensuring the process remained smooth and consistent.
- Final Adjustments: Matt addressed edge cases where the user might cancel an action or reset a form, ensuring that the variable reset to its default value in those cases too.
Conclusion
While Canvas Apps doesn't offer a direct way to remove the delete icon for attachments, Matt's approach with global variables is a clever workaround. By using conditional logic, variables, and notifications, he successfully ensured that users could edit records and add attachments without being able to delete them. This solution is perfect for users facing similar challenges and looking for a creative way to handle attachment management in Canvas Apps.
For more practical tips and tutorials, make sure to subscribe to Pragmatic Works’ training resources and stay up to date with the latest in app development!
Sign-up now and get instant access
ABOUT THE AUTHOR
Matt Peterson is a Trainer for Pragmatic Works specializing in the Power Platform. He graduated from the University of North Florida in 2006 and comes with 15 years of teaching experience in high school algebra. Matt earned the accomplishment in 2013 of being named the Florida Gifted Teacher of The Year. His primary focus is helping our customers learn the ins and outs of Power Apps and Power BI.
Free Community Plan
On-demand learning
Most Recent
private training

Leave a comment