If you are creating a file from Attachment from a Dynamics 365 CRM record and trying to load it in SharePoint and it doesn’t get created/read correctly?
Although, it might appear it was correctly uploaded, it might not open correctly and could look like this.
Consider this scenario – You want to store the Documents that you attach in Notes to SharePoint.
- Let’s assume you are uploading this PDF document on the Note and now you want to upload this to SharePoint.
- And you have a Flow to send this document to SharePoint which runs when you create a Note in Dataverse (Dynamics 365 CRM)
Now, the Create file action in SharePoint will look something like this –
If you use the new Dataverse [green] connector to pick up the attachment from the Note created in Dynamics CRM –
It’ll let you add the Document to the File context in SharePoint’s Create file action.
This is triggerOutputs()?[‘body/documentbody’] if you hover over it.
- And upon running this Flow, the document will be created in SharePoint.
- But when, you open the file, you’ll find this error that you can’t read the file although it appears that is was uploaded correctly.
- And also, the browser can’t open it either even if you download it.
Use base64ToBinary conversion
Here’s a step to create a File in SharePoint in your mentioned SharePoint library –
- In order to correctly pass this through, use the base64ToBinary expression in the Create file’s File Content field.
- And in base64ToBinary, put the Document so that it looks like this – “base64ToBinary(triggerOutputs()?[‘body/documentbody’])“
- And when you re-run the test, the document will be created in the same way.
And now when you open it, it’ll open properly.
Hope this solves the issue!
Dataverse (Legacy) connector
Here’s a difference you’ll notice in when you are using the Dataverse (Legacy) [gray colored] connector –
- If you are using the older Dataverse Legacy connector to pick your file from Dynamics 365.
- And try to add it to the Create file in SharePoint’s connector –
- It’ll let you add it but not let you save it.
You’ll face a validation error – “Flow save failed with code ‘OpenApiOperationParameterValidationFailed’ and message ‘Input parameter ‘body’ validation failed in workflow operation ‘Create_file’: The parameter with value ‘”@triggerOutputs()? [‘body/documentbody’]”‘ in path ‘body’ with type/format ‘String/bytes’ is not convertible to type/format ‘String/binary’.’.“
Here’s a detailed post of a scenario posted by my friend Linn: https://linnzawwin.blogspot.com/2021/02/handle-base64-and-binary-file-content.html
Hope this was helpful! Here are some more Dynamics 365 posts which you might be interested in –
- Enable SharePoint Online integration Dynamics 365 | Power Platform Admin Center
- Dynamics 365 Storage Utilization | Dataverse Storage | Power Platform Admin Center
- Use Hierarchy in Roll Up Fields in Dynamics 365 CRM
- Filter records in a View owned by a Team you are a member of | Dynamics 365 CRM
- Get GUID of the current View in Dynamics 365 CRM JS from ribbon button | Ribbon Workbench
- Dynamics 365 App For Outlook missing on SiteMap in CRM? Use shortcut link [Quick Tip]
- Import lookup referencing records together in Dynamics 365 CRM | [Linking related entity data during Excel Import]
- Excel Importing Notes (Annotation) entity in Dynamics 365 CRM
- Enable/Disable the need to Approve Email for Mailboxes in Dynamics 365 CRM CE
- Call Azure Function from Dynamics 365 CRM using Webhooks
- Show Ribbon button only on record selection in Dynamics CRM
- Accessing multiple occurrences of a field in Business Process Flow using JS in D365 CRM