
The use case - creating a new attachment
The use case is simple - to allow users to provide a title and description (for the associated note) when creating a new attachment.
The problem
When you create an attachment through a model-driven app, you can add a title and description to the associated note.
Here is a quick demo:

However, when you create an attachment through a canvas app, it creates the attachment record and the associated notes record but you don't have the opportunity to provide a title and description for the same. The title of the note defaults to the attachment file name.
Here is a quick demo:

The solution
Follow these steps:
- Add an edit form and set its Datasource to the appropriate table (Accounts in our example)
- Set the Item property of the form to the appropriate record
- Select only Attachments in the Fields property of the form
- Blank out the Items property of the attachment control
- Set the Max attachments property to 1
- Add two text boxes, one for title, and one for description or add an form and connect it to the Notes table
- If you added a form in step 6, select Title and Description fields and remove all the others
- Set the OnSelect of a button to the following code
SubmitForm(frmAttachments); Patch( Notes, First( Sort( Filter( Notes, Regarding = galAccounts.Selected && 'Created By'.User = LookUp( Users, 'User Name' = User().Email ).User && 'Is Document' = 'Is Document (Notes)'.Yes ), 'Created On', SortOrder.Descending ) ), { Title: txtNewNoteTitle.Value, Description: txtNewNoteDescription.Value } ); ResetForm(frmAttachments); ResetForm(frmNewNote);
Here is a quick demo:

Thus, with the above setup, we can create attachments through a canvas app with user entered title and description.
2 thoughts on “How to add a title and description when uploading an attachment in canvas apps”