The way I feel about Power Automate Flow is a perfect example of the love-hate relationships. Yes, I can do much more than I used to be able to do in the classic workflows. However, every now and then I run into something that seems simple, but that ends up being an exercise in google searching, forums browsing, intuition-based Flow development, and, of course, in the intense self-control.
The subject of today’s exercise was the following question posted in the community forums:
Well, this seems simple, and it is sort of simple once it’s been done, but it took me a while to figure out how to do it.
Here is how the Flow looks like:
There are a few things to consider:
- I can create an email record using “Common Data Service (Current Environment)” connector
- Once an email record has been created, I need an HTTP (Azure Ad) connector to add an attachment
- And, finally, I need an HTTP (Azure Ad) connector to send the email created earlier
Why do I need those Http with Azure Ad connectors?
This is because I could not figure out how to add email attachments/send emails directly through the CDS connector (and there were a few helpful links in the community forums which came up when I was looking for a solution. For example, this one has really helped: https://community.dynamics.com/365/f/dynamics-365-general-forum/360013/creating-activitymimeattachment-email-attachment-record-through-microsoft-flow).
With those connectors, however, you have to use a connection which is using correct base url. For example, in my case here is how “Send the email” step looks like – notice the request url:
In order for this to work, you’d have to create a connection so that base resource url and azure ad resource url would match the request url above:
Also, do keep in mind that all references are supposed to be in the following form:
With all that said, let’s just see how each step in my workflow is implemented:
1. Loading the file from Sharepoint
2. Creating an email (using “create record” action of the “Common Data Service(Current Environment)” connector)
I’ve hardcoded contact guid there, but you might, as well, get it from CDS using “List Record” action, for example
3. Converting email message id into “any” type – that’s a Compose action
This is so I could use it in the next step
4. Creating an email attachment (Http with Azure AD)
“Outputs” is from Get Email ID above
That base64 function is an expression: base64(outputs(‘Get_file_content’)?[‘body’])
I’ve also hardcoded file name & mimetype
5. Finally, sending an email (Http with Azure AD)
That’s it. Done. I think in the end I love Flows! Since, of course, I would not even be able to load that file from Sharepoint using a classic workflow, so I’d have to write some code, and it would take me quite a bit longer to figure out Sharepoint authentication etc.