When creating a table in Dataverse, we can add columns with specific data types. Like the date, text, multi lines of text, etc. Idem for a file data type. File data type columns are a primary data type intended to store a single image, note or attachment. However, keeping other forms of binary data is possible, and you can add multiple columns of this data type to a standard customizable or custom table—more information on Learn.

Question?
How can we download a file stored in a Dataverse column with the file type data format?

Solution Setup.

Dataverse Table
In Dataverse, we have a table that contains a file data file column. Below the screenshot, you will find an elementary table containing a file – columns of the data type “File”. In the “Demo Table,” we added a test value.

Demo table with file data column to store files.

Canvas App
A canvas app contains a gallery control with a datasource “Demo Table”. The following data types, File name, value, and download icon to download the file content are added to the gallery.

Gallery with data of the demo table.

We cannot directly download the file content from the Dataverse table from the canvas app. A possible solution to get the file content out of the Dataverse table is to use the Microsoft Dataverse Web API. More information about the OData protocol is here.

To retrieve the correct URL, go to the main form. You can right-click the file and copy the link.

Copy link

Determination of the URL:

HTTPS://[environment name].crm[x].dynamics.com/api/data/v9.0/[table logical name]([GUID of data row])/[File column logical name ]/$value

Anatomy

  • An environment name is a part of the environment URL. Microsoft generates it, or you have renamed it yourself. Example: org14575gde
  • crm[x]: Microsoft assigns regions based on your geographical location. Refer to the below table. 
North America (NAM)     crm.dynamics.com
United States Government Community Cloud (US GCC) Highcrm.microsoftdynamics.us
Microsoft Cloud Germany (DEU)crm.microsoftdynamics.de
South America (LATAM/ SAM)crm2.dynamics.com
Canada (CAN) crm3.dynamics.com
Europe, Middle East, Africa (EMEA/ EUR)crm4.dynamics.com
Asia Pacific (APAC/ APJ)               crm5.dynamics.com
Australia (OCE)crm6.dynamics.com
Japan (JPN)crm7.dynamics.com
India (IND)crm8.dynamics.com
North America 2 (US Gov GCC)crm9.dynamics.com
United Kingdom (UK/ GBR)crm11.dynamics.com
France (FRA)crm12.dynamics.com
South Africa (ZAF)crm14.dynamics.com
United Arab Emirates (UAE)crm15.dynamics.com
Germany (GER) crm16.dynamics.com
Switzerland (CHE)              crm17.dynamics.com
China (CHN)crm.dynamics.cn
  • Table logical name: can be found if you open the properties of the table.
  • Data row GUID: It is equal to the demo table id in this example.
  • $value: get the raw value of the property.
  • File column logical name: can be found if you open the edit screen of the column.

Let’s have a look at the code in the “onselect” – property of the download icon:

/* Get environment variable: Environment URL */
Set(
    gblVarEnvironmentURL,
    LookUp(
        'Environment Variable Values',
        'Environment Variable Definition'.'Schema Name' = "ppd_environmenturl",
        Value
    )
);
/*Update the local variable with the row guid.*/
UpdateContext({lclVarFileGUID: ThisItem.'Demo Table'});
/*Download the file content*/
Download(
    Concatenate(
        gblVarEnvironmentURL,
        "api/data/v9.0/ppd_demotables(",
        lclVarFileGUID,
        ")/ppd_file/$value"
    )
)

The file is downloaded from the canvas app when you click the download icon in play modus.

If you like this blog. Please give me a dumbs up or share the blog.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: