Upload Files to the Dynamics 365 Marketing Library with Power Automate

Inspired by a post from Megan V Walker on creating ICS fields for event registrations in ‘Customer Insights - Journeys’ (Dynamics 365 Marketing) but restrained by not being able to have a SharePoint file link accessed by external users (unauthenticated). I decided to see how we can use the ‘Library’ in Customer Insights - Journeys to host calendar (ICS) files so we can leverage the files publicly accessible links to allow download of a personalised calendar invite from a marketing email, sent via a custom trigger.

Creating the ICS file and all the associated magic is covered in Megans’ blog post, this post focuses on uploading the file into the Dynamics 365 Marketing library with Power Automate, rather than using a SharePoint share link.

I did stumble across this documentation on creating files in the library but it’s completely overcooked, only works for image files and is painfully vague/impossible to follow. I spent way too many hours hitting my head against a wall, to work out how to simplify it into two Dataverse actions but the file was refusing to upload to the marketing public storage. Full credits to George Doubinski and his passion for achieving things that are seemingly impossible/too hard, for working out that you need to update the name of the file to trigger the creation of the publicly accessible URL - you sir are a legend!

Realtime or outbound? Both!

This solution applies to both outbound and real-time marketing users because the Library is one of the very few things that is genuinely and truly shared between the many versions/identities of the platform. BUT be aware that the ‘Library’ is having a personality crisis. The single/plural name of the table in recent versions seems to be a little mismatched so when you are looking for the table in your power automate actions later it varies as to which one of these shows up (depending on which flow maker experience and action you are using). The important thing to check is that the schema/logical name should be msdyncrm_file.

I can’t upload calendar files into the library…

From the UI - there is indeed logic that prevents you uploading the calenda files, amongst many other file types.

…but you can with Power Automate!

Keep it classic

I’m sticking to the classic Power Automate designer for now because the modern one is too buggy and gives me motion sickness.

Where does it all start?

How you get to the point of needing to upload a file is entirely up to you, in the example of creating the event registration calendar file my previous steps would have been started from an event registration being created and the subsequent steps taken to create the ICS file in SharePoint.

Get the file metadata

You need to create the file somewhere before you upload it, in this case I’m using SharePoint but it could be OneDrive or something else. The action is ‘Sharepoint - Get file metadata’. The inputs need to be dynamic and based on the context of your flow to pick up the file you want to upload to the library.

Get the file contents

Get the latest version of the file with a ‘Sharepoint - Get file content’ action. Site address will be the same as above and use the ‘Id’ from the previous action.

Create a ‘File’ row

First we need to add a row into the Dataverse table for the Library which is knows sometimes called ‘File’ and other times called ‘Images’.

Using the action ‘Dataverse - Add a new row’ input the Name, Content type and File size (bytes) using dynamic inputs from the ‘Get file metadata’ action above.

Check the table name

You may also find you have multiple tables called ‘File’ or ‘Images’ so the best way to be sure is using the ‘Peek Code’ button and check the logical name is ‘msdyncrm_files’

Upload the file

Using the action ‘Dataverse - Upload a file or image’ we can now upload the file into the file column on the File table called ‘File Content’ ( did I mention file file file file file file file?). Super important thing here is to open the ‘Show advanced options’ and change the default ‘Content name’ from ‘Untitled’ to something else otherwise the file does not get uploaded into the asset library.

Use the ‘File identifier’ and ‘Name’ from your ‘Add a row’ steps as dynamic inputs. And the ‘File Contents’ from the ‘Get file content’ step from the ‘Content’ inputs.

‘Dataverse - Upload a file or image’
Table name: Images (msdyncrm_files)
Row ID: outputs('CreateFileRow')?['body/msdyncrm_fileid']
Column name: ‘File Content’
Content: body('Get_file_content')
Content name: outputs('CreateFileRow')?['body/msdyncrm_name']

Upload Image Thumbnail Preview

If the file is an image, you can also upload the image into the entity image field called ‘Main Image’ which then creates the thumbnail preview of the image for a better browsing experience in the library. Note that if you run this step on other file types the flow run will fail, hence first the condition then the action where applicable.

Control - Condition
If: outputs('Get_file_metadata')?['body/MediaType']
Starts with
image

‘Dataverse - Upload a file or image’
Table name: Images (msdyncrm_files)
Row ID: outputs('CreateFileRow')?['body/msdyncrm_fileid']
Column name: ‘Main Image’
Content: body('Get_file_content')
Content name: outputs('CreateFileRow')?['body/msdyncrm_name']

Don’t forget to ‘Show advanced options’ and update the content name

Check the File URL

Creating the file row and uploading the file to the ‘File Content’ file field is what triggers it to be sent to the marketing services and the publicly accessible URL is returned onto the file record - MAGIC

A big thank you to Megan for doing all the hard work creating the ICS file, and George for the Power Automate kicking support. When a publicly accessible SharePoint link is not feasible, this is the way to do it!

Bonus tips for event registration calendar files

If you are using this automation for event registration calendar files, here’s a few extra tips on the automation that would be good to include

  • Send the calendar file link in reminder emails too by adding a Lookup on the event registration to the File (msdyncrm_file) table and populate this lookup with the unique ICS file

  • Keep the Library clean and free up space by creating a flow that runs daily to delete files linked to event registrations for events that have passed

  • Update the calendar files if the event changes (and update registered contacts to let them know!)

Previous
Previous

Include specific row (entity) references and all the data in Real-time marketing custom triggers

Next
Next

Converting Dataverse Choice(s), (Multi-select) Option Sets, or Picklists in Power Automate