How to use the Attachment control in PowerApps to send a file by mail

The purpose of this article is to explain how to use the attachment control in PowerApps to allow a user to attach a file before sending an email.

First of all thanks to @WonderLaura for her article that helps me in my solution. And here is the documentation about the attachment control

In PowerApps the Attachment control works by linking a SharePoint list (Or CDS) to a form. Thanks to PowerApps, when the file is chosen by the user, it’s content is saved inside a blob as well as it’s name. There is no need to save the form for that, this action is only needed when you want to save the file to SharePoint.

So we are going to use this feature to allow the user to chose a file and send it as mail attachment but without the need to save it to SharePoint first. The SharePoint list used here is only used to “connect” the form to something that can eventually host attachment. So it’s a bit like a ghost list πŸ™‚

The result of my empty/ugly app that select an attachment from local computer and send it via email

PowerAppsResult

In order to do that, start by creating a new empty App in PowerApps.

The dataSource

  • A SharePoint List named: MyFirstList with nothing more than the title. Attachment is enabled for this list
  • The list is empty

The reload button at the top (Optional)

  • OnSelect:

// refresh my datasource (Optional)
Refresh(MyFirstList);;

// Clear a local collection and collect the attachments of the first item of my list (Optional)
ClearCollect(colAttachments; First(MyFirstList).'{Attachments}’)

The form (Required)

PowerAppScreenTree

  • Add a new Edit Form
  • Choose MyFirstList as datasource
  • Select the Attachment Field
  • Important step: Change the Item property of the form for this value: First(MyFirstList)
PowerAppFormProperetiesData
  • The PiΓ¨ces jointes_DataCard2 properties (Unlock if necessary)
PowerAppsDataCardProperties
  • The DataCardValue8 properties (Unlock if necessary)
    • OnAddFile:
      //Refresh the local collection with the data of the control
      ClearCollect(colAttachments; DataCardValue8.Attachments)
    • OnRemoveFile:
      //Refresh the local collection with the data of the control
      ClearCollect(colAttachments; DataCardValue8.Attachments)

NB: Yes, it’s the same formula.

PowerAppDataCardValueProperties

At this point, when you launch the App, the Attachment control should be enabled and you should be able to select a file from your disk. The data of the file will be saved in the local collection. Here is an example:

PowerAppCollectionResult

The Button to send the email (required)

The button uses the Office365 connector with the SendEmail action.
For the attachment, it uses a Table with specific columns:
Name, ContentBytes, ‘@odata.type’.

That’s what we are going to create when the user click the button.

NB: I’ve not been able to send multiple attachments yet, so for now I just send the first or last item or the collection. The error when the attachment table contains multiple items: The managed blob uri is not owned by the current app’s BlobManager

Not yet figured it out…

  • OnSelect:

//Create a new Table
ClearCollect(FinalAttachments; {Name:Last(colAttachments).DisplayName; ContentBytes:Last(colAttachments).Value;’@odata.type’:””});;

// Send the email
Office365.SendEmail(“me@me.com”; “My Subject”; “My Body”; {Attachments:FinalAttachments})

That’s it, when the user click the button, it will create a new Collection with the 3 specific columns required for the Attachment and send it.

How to create a Multilingual Power Apps using a language file stored in SharePoint

This article will explain how to create a multilingual Power Apps based on a JSON language file stored in SharePoint.
The solution provided here is one of many available solution that can be built to implement multilingual Apps.

Here’s the final rendering:

Final Rendering

Step 1 – The Power App

For this example I will use a very simple PowerApp with only a couple of controls but it can be extended to many labels on many screens πŸ™‚

So here’s what my app looks like:

Multilingual App

It contains a couple of controls and a dropdown list to select the language the user wants to display.

Perform Step 2 and 3 and then come back here for the formulas used in the PowerApp

The formulas used to process the language file are pretty simple and looks like:

OnStart function to process the language file

Details of the formulas:

1) Save the profile of the current user in a global variable.
Set(MyProfile,Office365Users.MyProfileV2())

2) Run the flow created in Step 3 and save the result in a global variable
Set(LanguagePack,’Dev-GetLanguagePack’.Run());

3) Set a global variable with the current language based on the user settings or the default language found in the language file

Set(
CurrentLanguage,
If(
IsBlank(MyProfile.preferredLanguage),
First(
Filter(
LanguagePack,
IsDefault = true
)
),
First(
Filter(
LanguagePack,
Label = MyProfile.preferredLanguage
)
)
)
)

Now that we have the current language, we can use this variable to set the properties on our controls.

Controls formulas details

DropDown list select language

DropDown list select language
PropertyValue
ItemsLanguagePack.Label
DefaultCurrentLanguage.Label
OnChangeSet(
CurrentLanguage,
First(Filter(LanguagePack,Label = Dropdown1.Selected.Label))
)

Other Controls

ControlPropertyValue
LabelTextCurrentLanguage.Screen1.MainScreenTitle
Text InputHintCurrentLanguage.Screen1.HintText
ButtonTextCurrentLanguage.Screen1.Button

Step 2 – The JSON file

In this case I wanted the file to be editable by another team so I chose to store it in a document library. (Everyone that’s using the App should have at least read access on this file)

Here’s what the file looks like. It’s an example and as it’s JSON you can create your own model. For this example I wanted to keep it simple with 2 languages and a couple of labels on 1 screen.

Language file

Step 3 – The Flow to link the file to the App

In order for PowerApp to process a JSON string, it must comes from the response of a flow using the Response Action which must contain the schema of the JSON (otherwise you’ll get a boolean response).

The flow in itself is pretty simple and looks like that:

Flow to read the language file