Dynamics 365 CE with Field Service v 18.104.22.168, mobile project v 1.0.1322
One of the handy features in Field Service Mobile is the possibility to capture images and signatures. Despite the changes introduced in April 2019 to the storage costs for Common Data Service, SharePoint Online might be better suited for storing all the images that pile up from service and maintenance calls. If you’re not familiar with the changes from April 2019, be sure to read this post by MVP Jukka Niiranen.
OOTB all images taken on Field Service Mobile end up on the related Work Order’s Timeline. The record itself is under the Note entity. While this may work just fine in some cases, a more proper and confined location for images taken in the field is in many cases SharePoint Online. The hypothetical scenario that we’re solving involves taking a photo, copying it to SharePoint Online, creating a link to the file on the Timeline of the Work Order and removing the original attachment from the original Note record.
The Flow is fired off when a new Note with an attachment is created. Trigger Conditions are used to control that that Flow only fires off when Object Type objecttypecode is msdyn_workorder and Is Document isdocument is true. The expressions used are:
The next step is to use a get action so that we can get our hands on both the related Work Order as well as the Service Account. Another option would be to build things around a Billing Account so consider which is the right approach for you.
In this example, all files are stored on a Team site in SharePoint. The compose actions are more a personal preference and made building the Flow a bit easier for me. The first compose is for the document folder in SharePoint. The output of this compose is referenced later on in the Save photo in SharePoint Online action.
The second and third compose actions around file name and file extension could be combined but in this case I found it easier to first compose the file name and then use the output in the Compose – File extension action. This made it easier to create the lengthy expression, which gets us the file extension. The extension is needed because an attachment can naturally be pretty much anything and we want the attachment to end up in SharePoint uncorrupted. The expression used is:
A huge shout out to the Flow community, which has helped me with so many expressions. I’d probably still be solving this one without the Flow community and this forum post.
It’s finally time for some SharePoint magic. First, new folders are created in SharePoint if the related Service Account or Work Order do not already have one. Don’t worry; this action won’t create duplicate folders. The second action saves the attachment in the folder related to the Work Order. A base64ToBinary expressions needs to be used to save the file and the expression is as follows:
The final actions create a Note without the original attachment and delete the original one with the attachment. The description from the original Note is copied to the new one, together with a link to the attachment in SharePoint.
As always, this Flow can be downloaded from the TDG Power Platform Bank. I hope this saves you some storage space and helps you store your attachments in a place that is better suited for them.