Microsoft Dataverse has several ways of managing file attachments, one of which is File or Image Column types. In this blog post, I will discuss how we can use Power Automate to overcome some of the challenges in creating automation that manages content stored within Dataverse File and Image Column Types.

One thing to note when using a File or Image column type is that the metadata for your file is stored within a related table (for example for Files it is the FileAttachment table).

So when attempting to manipulate the metadata associated with a file, e.g. a file name, you instinctively want to execute an update statement against the FileAttachment table that holds the metadata about this file. However, the FileAttachment table is a system table and does not support Retrieve or Update and hence your Power Automate flow will fail with an error.

There is more information about this limitation on Nishant’s blog here:

So immediately you’re presented with two immediate challenges:

  1. How do you inspect the metadata associated with your uploaded file? Especially as you cannot execute a retrieve command against the FileAttachment table that holds this metadata.
  2. And how do you make changes to the metadata and commit them back to Dataverse if you cannot execute an update command?

To solve these challenges within Power Automate, I will use the following example in which I rename an uploaded file with a new file name.

In short, the following Flow Example upon upload (i.e. trigger of Update against the File column), will perform the following actions:

  1. Call the same record to retrieve the filename, in order to identify the file extension type (e.g. .pdf)
  2. Download this file (hold in memory)
  3. Set a custom column parameter so that our flow does not run into an infinite loop, and finally
  4. Re-upload the file with the new file name

Flow Example (Renaming a File using a Power Automate Flow)

Create Column (File) if you have not already.

Create Column (Choice Yes/No, Default No) called Flow Triggered

This prevents the flow from entering an infinite loop as it will perform an update on the same column.

Create a New Automated Cloud Flow

Add Select Columns and Filter Rows as depicted.

The select columns limits the flow trigger to just on upload of a file. The filter row prevents an infinite loop within the flow when the flow ultimately updates the same column.

Add another Step (Get a Row by ID)

The Get a Row step is required as the actual file name is not present from the Row Added / Modified trigger.

Add a Compose Step with the following inputs.
slice(body('Get_a_row_by_ID_(to_retrieve_the_File_Name_String)')?['lyf_uploadedfile_name'], indexOf(body('Get_a_row_by_ID_(to_retrieve_the_File_Name_String)')?['lyf_uploadedfile_name'], '.'))

This Compose step will perform a slice to obtain the extension of the filename which will be required when renaming.

Add a Download a file or Image step.

This step will download the uploaded file to memory for reuse in subsequent steps.

Add an Update a row step.

This step will update the flow triggered value to Yes, so that it won’t enter an infinite loop when we reupload with the correct filename.

Add a Upload a file or an image step.

This step will upload the content from the previous step (download a file or image) but with a new name (Content name). The new name can be anything you like, e.g. CorrectedFileName followed by the extension from previous Compose step.

Testing the Flow

Summary

Hopefully Microsoft add additional actions to Power Automate that will enable efficient renaming or updating of metadata with File and Image type columns in the future, but at least you have an idea on how you can do this currently within Power Automate. If you have any questions or feedback please do not hesitate to contact me on LinkedIn.