CDS connector
There are many blogs explaining how to fetch email attachments from CRM and uploading them to Sharepoint using the old Dynamics 365 connector. But since this connector has been announced as deprecated in April 2019, I tried to achieve the same using the Common Data Service connector.
My use case is to upload e-mail attachments to sharepoint, in case an e-mail contains attachments and it is linked to an opportunity.
So first we define the following trigger:
Then we add a condition to check, weither the e-mail is linked to an opportunity:
As a next step we query all attachments related to this e-mail, but wait there are two entities called "attachment" offered:
So let's try the first one:
And what we get back is some metadata about the attachment, but not the filename and the body of the attachment, we are looking for:
But at least we are a step closer to our attachments. Lets try the second "attachment" entity offered in the list/get records action, with the information returned from the first request:
But unfortunately we end up with a bad request, informing us that the "retrieve" function is not supported for the attachment entity:
Alternative - Web API
So lets try out another alternative and see if we can utilize the Web API for that. First we add the following action:
If you use this action for the first time, you have to define the connection properties:
Once connected we define our request for the Web API:
This returns a JSON like that:
As a next step we add a "Parse JSON" action and add the result of the HTTP request in the "Generate from sample" menu. This creates a schema like below:
As a last step we loop over the result and upload the files to Sharepoint. It is important to consider, that the attachments are stored as base64 in the CRM database, so you have to convert them to binary, before you create the files in Sharepoint.
Finally our e-mail attachment has been uploaded to Sharepoint:
BTW:
Of course the folder path would not be hard coded like in this short example and you would add additional steps, where you would create the document location in CRM, add additional checks, if attachments are returned in the response to our http request a.s.o.
Comments
Post a Comment