Bank Statement Automatic Reconciliation using Power Automate and SharePoint in D365 Finance and Operations (D365 F&O)

Contents

Requirements

An automated solution for processing bank statements in Dynamics 365 Finance and Operations (D365 F&O) using Microsoft Power Automate and SharePoint. Below mentioned are the expected flow for the requirement.

  • Bank statements will be received via email.
  • Power Automate will automatically download the attached bank statement from email and drop it into the SharePoint designated location for processing.
  • D365 F&O will check the SharePoint folder and detect the arrival of new bank statement files.
  • The system will read and create statement upon detection.
  • If any errors occur during the file upload process, D365 F&O will move the affected files to a predefined "Error" folder. Users will be able to review this folder to identify and investigate any failures.
  • Successfully processed files will be moved to a "Completed" folder in the SharePoint for future reference and audit purposes.

Suggested solution

(The document seems to jump directly into prerequisites and steps after this heading. If there was specific content for "Suggested solution", it should be added here.)

Prerequisite

  • Power Automate access and subscription.
  • SharePoint admin access.
  • Azure admin access to run the PowerShell command.
  • Import ER model for the bank reconciliation (Custom or MT940 standard).

Steps

1. Complete ER setup for the bank reconciliation

Here I am using custom bank statements format in the ER for the reconciliation. Bank not providing MT940 format for this customer.

Placeholder for Image: ER Configuration - TSCUpdated Format

Standard reconciliation model extended and added new format mapping for the custom design.

2. Map the Format in the bank module

Placeholder for Image: Navigation to Bank Statement Format
Placeholder for Image: Mapping ER Format to Bank Statement Format (TSCModelMapping)

Map the ER format to the bank statement format in the cash and bank module in D365.

3. Map the format In the Bank master

Placeholder for Image: Bank Master Reconciliation Setup

4. Connect the SharePoint with D365

a. Establish the write and delete access to D365 finance and operation in SharePoint.

One time registration process

In Dynamics 365 finance and operations version 10.0.40 and later, when the SharePoint user authentication feature is enabled, your organization needs to perform a one-time setup to use the SharePoint integration for non-interactive batch scenarios. This is because the Microsoft-managed high-trust connection between the finance and operations environment and SharePoint has been deprecated.

With this updated SharePoint authentication mechanism, batch connections utilize application access. As this access is not granted by default for tenants, an Entra ID tenant administrator needs to be manually grant access one time for the tenant. This can be done by running the following PowerShell commands to provide the required application consent for finance and operations batch scenarios to connect to SharePoint.

Run PowerShell as administrator in the local system (any laptops)

Run below codes in PowerShell. Suggested to keep PowerShell latest version, here my version is v7.5.0

My test PowerShell command image

Install the Microsoft Graph

Select the respective folder in the local machine using PowerShell for the installation of the file and run the below command.

Install-Module Microsoft.Graph -Scope CurrentUser

Import the module to run command

Import-Module Microsoft.Graph.Applications

Connect Graph using PowerShell

Connect-MgGraph -TenantId microsoft.onmicrosoft.com -Scopes 'Application.ReadWrite.All'

*Replace the ‘microsoft.onmicrosoft.com’ with user tenant ID.

Once click the enter button for the above command a browser will open for the authentication.

Placeholder for Image: Microsoft Account Picker for Authentication

For the authentication, use the azure portal admin account.

Once connected successfully below message will receive:

Placeholder for Image: Successful Microsoft Graph Connection Message

Activate service principal

Run below 3 lines of command (copy and paste)

# These AppIds do not change as they are the first party application IDs
$erpServicePrincipal = Get-MgServicePrincipal -Filter "AppId eq '00000015-0000-0000-c000-000000000000'"
$sharePointServicePrincipal = Get-MgServicePrincipal -Filter "AppId eq '00000003-0000-0ff1-ce00-000000000000'"
$spAppRole = $sharePointServicePrincipal.AppRoles | where {$_.Value -eq 'Sites.ReadWrite.All'}

# Assign the SharePoint 'Sites.ReadWrite.All' permission to the Microsoft Dynamics 365 finance and operations application
New-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $erpServicePrincipal.Id -PrincipalId $erpServicePrincipal.Id -ResourceId $sharePointServicePrincipal.Id -AppRoleId $spAppRole.Id

“Now the Connect with D365 and SharePoint is established for the delete and update“

b. Map the SharePoint in D365

Placeholder for Image: Navigation to Document Management Parameters
Placeholder for Image: Document Management Parameters - SharePoint Setup

In the default SharePoint server, field mention the SharePoint URL. And click on the Test interactive SharePoint connection and Test batch SharePoint connection.

If the connections are established. Below message will receive.

Placeholder for Image: Successful SharePoint Connection Message

5. Create folders in SharePoint

Placeholder for Image: SharePoint Folders - Bank Reco, Completed, Error

Created 2 folders inside the Bank Reco folder.

When new bank statement came from the bank through mail, power automate will bring that file to Bank Reco folder in the SharePoint folder, if the file processed successfully, file automatically move to the completed folder. If any error occurs that file will move to the error folder. So, user can easily identify the error files.

6. Create SharePoint locations in D365

Here we are mapping the SharePoint folders in D365.

Placeholder for Image: Navigation to Document Types
Placeholder for Image: Document Types Setup - General Tab

Mention the code for the file in the Type code field. Here I am given as Bank Statement, BS Completed and BS error.

In the Name field mention the name of the file.

In location, Select SharePoint.

Click on the Edit button in the SharePoint address field.

Now it will connect to the SharePoint site mentioned in the 4.b Session.

Placeholder for Image: Folder Selection from SharePoint in D365

Here we can see all the folders, sites and forms in the SharePoint folder. Navigate and select the correct folder.

Click Ok

Placeholder for Image: SharePoint Address Updated with Document Removal Options

Now the address is updated in the SharePoint address field.

Like the same create all 3 folders: Bank statement, BS Completed, BS Error

Placeholder for Image: All Document Types Created (Bank Statement, BS Completed, BS Error)

7. Attach the source file to the ER format

Now we are attaching the document type to the ER format. When we run the ER format. It will pick the file from the defined source only.

Placeholder for Image: Navigation to Electronic Reporting Source
Placeholder for Image: Selecting ER Format in Electronic Reporting Source

Select the ER format from the drop down.

Click on Save button

Placeholder for Image: File Source Configuration in ER Source

Click New in the file source area.

In the name field mention the name for the file

In the file name mask, Type the bank statement extension(*.CSV). If the extension is not mentioned here, system will pick all the file types in the folder for the process.

Click on the settings button above the line.

Placeholder for Image: Source Settings for SharePoint in ER

Enable the SharePoint toggle.

Select the document types as mentioned above from the drop down.

8. Create a Bank statement Batch Job

Placeholder for Image: Navigation to Bank Statements
Placeholder for Image: Import Statement Option in Bank Statements
Placeholder for Image: Import Bank Statements Batch Job Setup

9. Checking the file movements in D365

Placeholder for Image: Navigation to File States for the Sources
Placeholder for Image: File States for the Sources - Initial View
Placeholder for Image: File States for the Sources - Imported Status and Logs
Placeholder for Image: SharePoint Bank Reco Folder after Processing (reports.xlsx might be an example file)
Placeholder for Image: SharePoint Completed Folder with Processed File
Placeholder for Image: Bank Statement View in D365 after Import

10. Configure Power automate to move the files to SharePoint from Email

(The document ends here. Details for this step would be added if available.)