The Holy Patch Function - Alex Ward

The Holy Patch Function - Alex Ward

If you had asked me how I would have gone about doing this previously, I would have probably suggested using a cloud flow to take the file from a canvas app and save it against a file column in Dataverse.??

However, it turns out it's pretty simple to do through a patch function.?

To set the scene, the canvas app I built was for bulk uploading rows into an application table, where each application would have an associated CV. Therefore, I had a gallery filled with the applicants' details and an attachment control where the user could quickly drag and drop CVs into the app.?

Annoyingly, the attachment control cannot be added through the normal insert dropdown. Instead, you must add a form with a data source that has an attachment column (like a SharePoint List) and copy the control out.?

In order to get the CV to patch into the file column when the file was added to the attachment control and not require any further input from the user, I added the following patch statement to the 'OnAddFile' property of the attachment control:


As the attachment control is within a gallery, we can reference the row we need to update as 'ThisItem', with 'CV' being the file column we want to update. Essentially, it expects a row, made up of ‘Value’ and ‘FileName’. As the attachment control can technically store multiple files, I used the 'First' function to take the uploaded file (of which there will only ever be one) and then access the required properties using dot notation. You can configure maximum attachments and more as detailed in the documentation:??

learn.microsoft.com/en-us/power-apps/maker/canvas-apps/controls/control-attachments ?

What if the user removes the file? It turns out we can use the 'OnRemoveFile' property to do the exact opposite and clear out any file we've added to the file column:?


It’s as simple as that; the file column will now remain in ‘sync’ with whatever file we add to the attachment control!?

要查看或添加评论,请登录

Power 365 Solutions的更多文章

社区洞察

其他会员也浏览了