Step-by-Step Guide: Building Dynamics 365 Finance AI Agents | ChatFin

Step-by-Step Guide: Building Dynamics 365 Finance AI Agents

Leverage the power of the Microsoft ecosystem by building custom AI agents that interact with Dynamics 365 Finance & Operations using OData and Power Platform.

What You'll Build

Develop a high-performance integration between generative AI models and your D365 Finance instance to automate AP invoice processing, credit control, and financial reporting.

  • Seamless OData connectivity for real-time data access
  • Intelligent invoice matching using AI logic
  • Automated collections emails personalized by AI
  • Custom connector logic for Power Automate and Logic Apps
  • Secure Azure Active Directory (Entra ID) authentication
Dynamics 365 AI Architecture

Microsoft Dynamics 365 Finance is a powerhouse, but realizing its full potential requires automation. Users often spend hours navigating menus for routine tasks. By building a custom AI agent, you can bypass the UI and interact directly with the data entities that drive your business.

Phase 1: OData & Data Entities

Dynamics 365 exposes its data through OData (Open Data Protocol). Your AI agent will use this standard REST-based protocol to read and write data.

Identifying Key Data Entities:

For a finance agent, you will primarily interact with:

  • GeneralJournalAccountEntry: For GL transactions.
  • VendInvoiceJournalHeader/Line: For AP automation.
  • CustTable & CustTrans: For AR and collections.

Python Connection Example:

import msal
import requests

# Entra ID (Azure AD) Configuration
config = {
    "authority": "https://login.microsoftonline.com/YOUR_TENANT_ID",
    "client_id": "YOUR_CLIENT_ID",
    "scope": ["https://YOUR_D365_URL/.default"],
    "secret": "YOUR_CLIENT_SECRET"
}

app = msal.ConfidentialClientApplication(
    config["client_id"], authority=config["authority"],
    client_credential=config["secret"]
)

result = app.acquire_token_for_client(scopes=config["scope"])
access_token = result.get("access_token")

# Query D365 Data
headers = {'Authorization': 'Bearer ' + access_token}
endpoint = "https://YOUR_D365_URL/data/Vendors?$top=5&$select=VendorAccount,Name"
response = requests.get(endpoint, headers=headers)
print(response.json())

Phase 2: Intelligent Collections Agent

One of the highest ROI applications is an AI agent for collections. The agent monitors aging reports (CustTrans), identifies overdue invoices, and drafts personalized emails to customers.

Workflow Logic:

  1. Fetch: Agent queries OData for invoices > 30 days overdue.
  2. Analyze: Agent checks customer history and risk profile.
  3. Generate: LLM writes a polite reminder email referencing specific invoice numbers.
  4. Action: Draft email is pushed to Outlook or D365 via Graph API.
Collections Workflow Scenarios
  • Soft Reminder: If invoice is 5 days overdue and customer credit utilization < 50%, send "friendly reminder" via email.
  • Escalation Trigger: If invoice is 30 days overdue OR collection letter was sent 7 days ago with no reply, draft escalation email to Sales Account Manager with invoice context.
  • Payment Plan Proposal: If customer replies "cash flow issues," agent proposes standard installment plan (50% now, 50% net 30) based on predefined policy.
  • Dispute Recognition: If customer replies "wrong amount," agent reads content, tags transaction as Disputed in D365, and creates Case for deduction management team.

Phase 3: Integration with Microsoft Fabric

For deep analytics, connect D365 Finance data to Microsoft Fabric (OneLake). This allows your AI agent to query massive datasets using SQL or DAX without impacting the operational ERP performance, enabling real-time "Chat with your Finance Data" capabilities.

Fabric Data Patterns

  • Cross-Entity Intelligence: Join D365 Finance data with D365 Sales (CRM) data in OneLake to calculate Customer Lifetime Value (CLV) including support costs.
  • Unstructured Data Merging: Ingest PDF vendor contracts into OneLake, extract payment terms using Azure Doc Intelligence, and compare against actual D365 payment performance.
  • Predictive Cash Flow: Use Fabric Spark notebooks to run ML models on 5 years of `CustSettlement` history to predict next month's collections with 95% confidence.

Accelerate Your Dynamics 365 AI Journey

ChatFin offers deep integration with D365 Finance & Operations, providing turnkey AI agents for AP, AR, and Forecasting.

Next Steps

Start by building a read-only "Finance Assistant" that answers questions like "What is our current cash position?" or "Who are our top 10 overdue vendors?" before moving to active automation agents.