Amey Holden

View Original

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!

…but you can with Power Automate!

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.

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']

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!)