Attaching File from SharePoint Location in Email using Power Automate while working on D365 CRM

What is Issue?

When working on D365 CRM, Some processes needs to send notification as well as approval mails to particular users. In these emails some time users want the files to be attached which is uploaded for any particular record in CRM. Developer faces issue to get the file from SharePoint, because of very few columns available in SharePoint which is created by D365 CRM to SharePoint Integration. So the issues are like how to get the file from SharePoint and attach it email?

The Reason-

Using Workflow or custom plugin it will be much time consuming and also complex coding required with this approach. Developer can choose this approach for sending out simple notifications, emails. But when the requirements comes to file attachment from SharePoint or any other cloud location it will be difficult to handle with this approach. Also if the file is in SharePoint location which is configured using Document management in CRM, location will have limited set of columns, so it becomes difficult to query the SharePoint site using API also.

Solution-

For the first issue, which approach to choose in these scenarios-
Microsoft is already recommending users to use Power Automat instead of CRM Workflows. Power Automate is having multiple connectors and actions available which reduces the coding as well as time efforts. So we can choose Power Automate.

Now second Issue, How to get file from SharePoint location which is configured using Document Management in CRM?
As I already mentioned, Power Automate already having hundreds of connectors and actions, we can use the Get File Action in Power Automate. Now again you will be worried about how you can get particular file from this location as Tittle or any other field will not help here. So we can use FileLeafRef column filter for that.

Lets take scenario –

When user have opportunity where he uploads the template for Opportunity Activity logs in Document section. But before closing opportunity user needs the log template approved by his manager. Suppose there is flag when user submits the approval request.

  1. Trigger action for my Power Automate flow will be “Microsoft Dataverse when a row is added, modified or deleted where I will set row filter as AwaitngApprovalflag eq 1
  2. Now we need to initialize the Array which will work as byte array to store the file retrieved from the SharePoint.
  3. Add new SharePoint action “Get File(Properties Only)” and set SharePoint details with Filter Query – FileLeafRef eq “filename.xlsx” (this will be my log file template name)

4. Now add the SharePoint action “Get File Content” and set site address as SharePoint site, File Identifier as identifier from last action i.e. “Get File (Properties Only)”. This will automatically add Apply to Each loop.
5. Append the Array variable with File Content and file name from the above action “Get File Content”.
Example-
{
“FileName”:”fileName.xlsx”,
“ContentByte”:FileContent
}

7. Add action “Send Email With Option” and set participant and email body, and other details. In attachment section set the Array Variable which we initialized and configured with file content.

8. Add condition action and check the response from the manager in Email like he clicked on Approve or Reject button in email. and based on condition perform the next actions on your D365 CRM Record.

9. The Complete Flow looks like-

Hope this will help…
Enjoy Ms CRM!!!

Follow on Facebook- FB: MSCRM16Tech

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s