(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to create a form with conditional attachments in Power Apps / Power Platform

João Barros 28 de October de 2026 4 min read

Creating a form that asks for attachments only when necessary is useful to reduce redundant data and guide users. This tutorial shows how, in Power Apps / Power Platform, to build a Canvas App that presents conditional file fields and saves attachments to SharePoint or Dataverse.

Prerequisites

  • Account with access to Power Apps (Canvas Apps license).
  • A SharePoint list or a Dataverse table for records (e.g.: list "Registos").
  • A Power Automate flow (optional) to move attachments or process larger files.
  • Basic knowledge of Canvas Apps: screens, galleries, forms and collections.

Step 1: Create the data source (SharePoint or Dataverse)

Decide where you will store the records. Example with SharePoint: create a list called "Registos" with columns: Title (Text), Tipo (Choice) and Comentarios (Multiline). For conditional attachments you can use the list's native attachments feature or store files in a separate library and save the link.

// Exemplo: estrutura mínima da lista SharePoint
Lista: Registos
Colunas: Title (Texto), Tipo (Escolha: Produto, Serviço), Comentarios (Multilinha)
Ativar anexos na lista

Step 2: Create the Canvas App and connect the data source

Create a blank Canvas App (Phone or Tablet) and add the connection to the SharePoint list (or the Dataverse table). Insert an EditForm connected to "Registos" and the fields Title, Tipo and Comentarios.

// No Power Apps Studio
Insert > Forms > Edit Form
DataSource = Registos
Fields = [Title, Tipo, Comentarios]

Step 3: Add conditional attachment control

If you use the EditForm native attachments feature, you can show/hide the Attachments control based on the Tipo field. Alternatively, use a custom file control (AddMediaButton or a separate Attachment control) and store the files in a collection until submit.

// Exemplo usando AddMediaButton para recolher ficheiros condicionalmente
// Adiciona um AddMediaButton chamado btnAddFile e uma Gallery chamada galFiles
// Colecção para guardar ficheiros temporários
OnAddFile: Collect(colFiles, {Name: Last(AddedMedia).Name, Content: Last(AddedMedia).Value})

// Visibilidade do botão controlada por Tipo
btnAddFile.Visible = (DataCardValue_Tipo.Selected.Value = "Serviço")

Step 4: Show list of added files

Create a simple Gallery that shows the items in colFiles to allow removing or viewing the file name before submitting.

// Gallery Items
galFiles.Items = colFiles

// Remove button in the Gallery template
OnSelect = Remove(colFiles, ThisItem)

Step 5: Submit the form and save attachments

When the user submits the form, first save the record to SharePoint/Dataverse. If you use SharePoint with native attachments, you can use FormMode and SubmitForm; for files stored separately, create the item and then upload to the library and update the link in the record.

// Botão Guardar - lógica simplificada
// 1. Submeter formulário para criar o registo
SubmitForm(frmRegisto)

// 2. Quando o formulário for bem-sucedido, usar OnSuccess para processar ficheiros
// OnSuccess do frmRegisto
If(CountRows(colFiles) > 0,
   ForAll(colFiles,
     // Exemplo de criar ficheiro em SharePoint numa biblioteca chamada 'Anexos'
     // Usa a função Power Apps: Patch com SharePointAttachment não é suportado directamente
     // Recomenda-se usar Power Automate para upload; aqui mostramos chamada a um Flow
     'FlowUploadFile'.Run(RegisterID, ThisRecord.Name, ThisRecord.Content)
   )
);

// Onde RegisterID = frmRegisto.LastSubmit.ID

Step 6: Create the Power Automate flow to receive files

Since Power Apps does not write binaries to libraries easily, create a Power Automate with trigger "Power Apps" that receives parameters: RegisterID, FileName, FileContent (base64). The Flow uses the "Create file" action in SharePoint and updates the list/record if needed.

// Passos essenciais no Flow
Trigger: PowerApps
Action: Create file (SiteAddress, FolderPath, FileName, FileContent) // FileContent em base64
Optional: Update item (Registos) para acrescentar link do ficheiro
Return: success/URL para Power Apps

Verify the result

Test the scenario: choose Tipo = "Serviço" and add files; choose Tipo = "Produto" and verify that the attachments button is hidden. Submit and confirm that the item was created in the SharePoint list and that the files appear in the library linked to the record. Common errors: files not uploaded because the Flow does not return success, insufficient permissions, or improperly formatted base64.

Conclusion

With this pattern you have a form in Power Apps that requests attachments only when applicable and saves them reliably using Power Automate for upload. Next steps: handle file size/type validation, show upload progress, and associate file metadata with the record. Tip: always test the Flow separately with sample data to debug file issues.