In Part One I talked about how to set up a new Flow trial and the key elements which make up Flows. In this one I will show my first attempt at creating a Flow (even though it failed) as it is a good, simple example.
My Mission: Bring Attachments Into CRM
The problem to solve was to bring attachments into Dynamics 365 (CRM) from a scanner. The client was using Dynamics CRM 4 and had written some code such that a scanned document was sent to an email address, with the “Contact ID” in the Subject of the email. The email then hit a CRM Queue, the code kicked in and the email attachments appeared under the Contact.
Obviously the client wanted a process similar to the old one to minimize disruption.
Starting With a Template
A good place to start in Flow is a pre-written template as this will save some of the configuration. There was no Exchange to Dynamics 365 template but there was an Exchange to OneDrive template which scraped the attachments from emails and put them in OneDrive.
A bit further down the screen is the Create Flow button which gives you a copy of the template Flow (deactivated by default) to work on. Click the Edit Flow button on the screen that appears to get into the details.
As you can see below, Flows are fairly straightforward. In this case there is an Office 365 Exchange Trigger which activates the Flow when a new email is received into the Inbox. A loop then kicks in which goes through each attachment in the email and creates a file in OneDrive in a specified folder.
What is also quite nice about Flows is, if you log in with an Office 365 account, it automatically connects to the relevant services i.e. Exchange and OneDrive.
Modifying the Template to Suit Our Needs
As can be seen in the previous screenshot, clicking the ellipsis (three dots) next to the Create file Action allows us to delete the action. In our case this is exactly what we need to do, replacing it with a Dynamics 365 (CRM) action.
Once the Action is deleted, you mouse over the same area and click the ‘+’ sign that appears. Selecting ‘Add an Action’ presents all Actions available in Flow. To get to Dynamics 365 click ‘See more’.
Sure enough, there are three Dynamics 365 options with the only thing to differentiate them being the icon. Ours is the first one, Dynamics 365 (not ‘for’ anything).
Dynamics 365 has a few options available for us and we have triggers on creation, updating and deletion.
In our case we chose to Create a new record (a Note).
Flow is clever enough to retrieve the entities and fields of CRM and also allows us to choose the key attributes of the source email and its attachments.
The final step is to update the Flow and activate it (which you can do on the screen that appears after updating).
Running the Flow and Seeing How it Went
Going to My Flows and selecting this Flow shows the summary screen, including when it has been executed. In our case, we simply send an email to the monitored Inbox and wait a few minutes. Unfortunately, in our case, the Flow fails.
We can click through to one of the failed runs to see the details, including the inputs and outputs of each step.
Interestingly, if we remove the Document and Mime Type, the Flow works fine so there is a bug with the creation of attachments. My guess is however emails manage attachments is not quite compatible with the way Dynamics 365 does.
The good news is there is another way and I will show this in the last part of this series. We will also learn about programming Flows without code.