This question has been going around on the power users community forums and I thought it would be nice to blog it because it is always gets tricky trying to save files from different data sources , so for this we have a single source the outlook connector and there is two destination.
- Sharepoint File
- Dataverse Email Attachment
Lets Get Started!
So the starting point is the Flow Trigger which is “When a new email arrives (v3)”
Then the next step is to get the Attachments from the Email by using the below steps:
- Loop on the attachments from the triggerOutputs
- Use Get Attachment (v2) to get each attachment
Then to save to sharepoint that was pretty easy .. Just using the outputs of the Get Attachments (V2) has worked from the first Go!
Name and Content Bytes!
What about dataverse?
So for DataVerse we are creating a new email activity and adding the attachments to it as below but it wasn’t straight forward adding the attachment.
Step 1: Easy : Create the Email Activity
Step2: Add the Attachment and here is a couple of tricks
- when you select the table name attachments there is 2 tables , make sure you select first one.
- Attachment(Attachments) just pass null from the Expressions Pane … Weird but how this is working.
- Entity: Do not select one of the available Options , just use enter a custom value and type email otherwise you will get an error.
The entity with a name = ‘4200’ with namemapping = ‘Logical’ was not found in the MetadataCache. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=3040485, MinActiveRowVersion=3040485, MetadataInstanceId=51707140, LastUpdated=2021-08-04 11:35:57.770
And when it came to setting the body ; it wasn’t as easy as passing the content bytes directly as with sharepoint ..
Attempt 1: Pass Content Bytes directly .. Error Received
The attachment body should be a valid Base 64 string
Attempt 2: Convert Content Bytes to base 64, No error received, file was attached but corrupted
Attempt 3: Binary ???!!! .. Weird but this is what worked for me run successfully and file was not corrupted.
Hope this is useful!