Canvas Apps Code Sample Controls Dataverse

How to add a title and description when uploading an attachment in canvas apps

A notepad with a pen to add a title and description to a note
A notepad with a pen to add a title and description to a note

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:

New attachment through a model-driven app
New attachment through a model-driven app

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:

New attachment through a canvas app
New attachment through a canvas app

The solution

Follow these steps:

  1. Add an edit form and set its Datasource to the appropriate table (Accounts in our example)
  2. Set the Item property of the form to the appropriate record
  3. Select only Attachments in the Fields property of the form
  4. Blank out the Items property of the attachment control
  5. Set the Max attachments property to 1
  6. Add two text boxes, one for title, and one for description or add an form and connect it to the Notes table
  7. If you added a form in step 6, select Title and Description fields and remove all the others
  8. 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:

New attachment with title and description through a canvas app
New attachment with title and description through a canvas app

Thus, with the above setup, we can create attachments through a canvas app with user entered title and description.

Recent articles

  1. How to show a combined gallery of notes and attachments
  2. What happens when you create an Attachment in Dataverse?
  3. How to work with Dataverse Attachments in canvas apps

2 thoughts on “How to add a title and description when uploading an attachment in canvas apps”

Leave a Reply