Purchase Order Automation: End-to-End Architecture Using Power Automate, Azure, and Sage ERP

1. Introduction — What Problem Are We Solving?

2. Solution Architecture Overview

The pipeline has five major stages, each handled by a specific technology:


Stage Technology
Email Intake & Trigger Power Automate Cloud Flow
Document Storage SharePoint via D365 Document Management
AI Data Extraction Azure Function + Azure Document Intelligence
Quotation Matching Azure Function + MySQL API
ERP Order Creation Power Automate Desktop + Sage Visual Integrator

Key design principle: No system directly writes to another system's database. All integrations go through approved interfaces and APIs.

3. Stage 1 — Email Intake & Trigger (Power Automate Cloud Flow)

This is where the process starts. Instead of a custom CRM plugin, a Power Automate Cloud Flow monitors Dynamics 365 for incoming emails.


How it works:


Trigger Conditions the Flow Validates:


Flow Actions After Trigger:


Key Technical Points for Blog:

4. Stage 2 — Document Retrieval & AI Extraction (Azure Function)

The Azure Function is the brain of the solution — it orchestrates everything from document retrieval to structured data output.


Step-by-step processing:


Step A — Authenticate & Download from SharePoint


Step B — Send to Azure Document Intelligence


Data Extracted:

Header-Level:


Line-Level (per line item):


Step C — Confidence Threshold Enforcement


Confidence Level Action
≥ 95% Auto-proceed
75–94% Flag for internal review
<75% Mark as extraction failure

Key Technical Points for Blog:

5. Stage 3 — Quotation Retrieval (MySQL API)

Once the PO is extracted, the system retrieves matching quotation data for comparison.


How it works:


Request Parameters Sent:


Response Data Expected:

Quotation Header:


Quotation Line Items:


Key Technical Points for Blog:

6. Stage 4 — Matching Engine (Core Business Logic)

This is the most technically complex stage. The matching engine is deterministic and explainable — every decision can be traced back to specific rules and scores.


Step 1 — Exact Match

If all pass → Verified = TRUE, proceed directly to ERP.


Step 2 — Weighted Similarity Match

A scoring model is applied across multiple dimensions:

Dimension Weight
Customer ID Mandatory (disqualifier if fails)
SKU Match 40%
Description Similarity 25%
Amount Similarity 20%
Quantity Similarity 15%

Similarity Logic:

Score Classification:


Score Classification
≥ 95% Verified
76–94% Suggested Match
< 75% No Match

Key Technical Points for Blog:

7. Stage 5 — Sage ERP Sales Order Creation

Verified or Suggested Match POs proceed to Sales Order creation via a UI automation path — not a direct API or database write.


Why Sage Visual Integrator (SVI)?


Integration Flow:

  1. Azure Function → Power Automate Cloud Flow

    • Function prepares the validated Sales Order payload in JSON.
    • Sends an HTTP trigger to a Power Automate Cloud Flow.
  2. Power Automate Cloud → Power Automate Desktop

    • Cloud flow calls a Desktop flow installed on a dedicated Virtual Machine.
    • Desktop flow runs in unattended mode using a service account — no human interaction required.
  3. Power Automate Desktop → Sage Visual Integrator

    • Desktop flow launches SVI.
    • Selects the predefined Sales Order import template.
    • Maps and populates all required fields.
  4. Visual Integrator Creates the Sales Order

    • SVI runs its own internal validation.
    • Creates the Sales Order in Draft/Hold state (configurable).
  5. Sales Order Number Returned

    • SVI outputs the generated Sales Order number.
    • Desktop flow captures and passes it back through: Cloud Flow → Azure Function → D365 Case/Email Activity.

1.Working Directory for Sales Order Automation

This screenshot shows the main working directory used in the automation process. The folder contains all required components such as the input CSV file (sales_order.csv), batch file (RunImportJob.bat), export folder, and supporting scripts.

This folder acts as the central hub where Power Automate Desktop generates files and Sage ERP processes them.

👉All automation activities are executed from this directory.


2.Sales Order Input File Generated by Power Automate Desktop

This screenshot shows the sales_order.csv file generated by Power Automate Desktop. This file contains structured Sales Order data extracted and validated from the Purchase Order.

The CSV includes fields such as Customer Number, Customer PO Number, Item Code, Quantity, and Unit Price.

👉This file is used as the input for Sage Visual Integrator to create the Sales Order.


3.Batch File Execution for Sage Automation

This screenshot displays the batch file responsible for executing Sage ERP automation. The batch file is triggered by Power Automate Desktop and performs the following actions:

Blog content image

👉This batch file automates the entire interaction with Sage ERP without manual intervention.


4.Visual Integrator Navigation

This screenshot shows how to access the Visual Integrator module in Sage 100 ERP. Users navigate through:


Blog content image

Visual Integrator is used to create Import and Export Jobs for integrating external data into Sage.

👉This is the entry point for Sales Order creation.


5.Creating Import Job for Sales Order

This screenshot shows the Import Job Maintenance screen where a job named IMPORT_SO_PAD is created.


Blog content image

This job is configured to import Sales Order data into Sage ERP using the CSV file generated by Power Automate Desktop.

👉This job is responsible for inserting data into Sage.


6.Configuring Import Job in Sage

This screenshot shows the configuration settings of the Import Job.


Blog content image

Key configurations include:


👉This step connects the CSV file to Sage ERP for processing.


7.Mapping Fields for Sales Order Creation

This screenshot shows how CSV fields are mapped to Sage Sales Order fields.


Blog content image

Fields such as Customer Number, Customer PO Number, Item Code, Quantity, and Unit Price are mapped accordingly.

👉This is the most critical step because it defines how data is inserted into Sage.

👉 At this stage, when the Import Job runs, Sage Visual Integrator processes the CSV file and creates the Sales Order inside Sage ERP.

8.Creating Export Job for Sales Order Retrieval

This screenshot shows the Export Job Maintenance screen where the job EXPORT_SO_PAD is configured.


Blog content image

This job is used to retrieve Sales Order details after creation.

👉 It helps in validating whether the Sales Order is successfully created.


9.Configuring Export File Path

This screenshot shows the export configuration where the output file path is defined.


Blog content image

👉 This file stores the Sales Order results.


10.Selecting Fields for Export

This screenshot shows the fields selected for export such as:


Blog content image

👉 These fields are written into the output CSV file.


11.Generated Output Folder

This screenshot shows the Export folder where the output file so_result.csv is generated after executing the Export Job.


Blog content image

👉 This confirms that the process has been completed successfully.


12.Sales Order Output File

This screenshot displays the contents of the so_result.csv file.


Blog content image

The file contains:


👉 This confirms that the Sales Order has been successfully created in Sage ERP.

👉 Sales Order is created inside Sage ERP when the Visual Integrator Import Job processes the CSV file generated by Power Automate Desktop.

Sales Order Field Mapping Highlights:


Field Source
Customer Number D365 Account
Customer PO Number Extracted from PDF
Ship Date Extracted from PDF
Quote Number Extracted from PDF
Match Score Computed by matching engine
Verification Flag Set by matching engine
Item Code, Qty, Unit Price Extracted line items
Case Number D365 Case

Key Technical Points for Blog:

8. Exception Handling & Resilience

Every stage has failure handling built in:


Scenario Handling
Duplicate PO email received Correlation ID check prevents reprocessing
Low extraction confidence Flagged for review, not discarded
No quotation match found Logged in D365, routed for manual handling
Sage unavailable Retry with exponential backoff
SVI validation failure SVI validation failure Logged + notification sent
VM offline Payload queued until VM is available
MySQL API down Azure Function returns error, PAF flow notified
Network issues Retry logic with backoff across all HTTP calls

9. Security Architecture


Layer Control
Authentication Azure AD App Registration (OAuth 2.0)
Secrets Management Azure Key Vault (no hardcoded credentials)
Access Control RBAC — least privilege on all resources
ERP Access Only through SVI — no direct DB access
Unattended Automation Dedicated, locked-down service account
Audit Trail Correlation ID + logs at every stage

10. Non-Functional Highlights (Worth Calling Out in Blog)

11. Key Architecture Decisions Worth Highlighting


These make good discussion points in a blog:

  1. Power Automate Flow over a custom plugin — Lower maintenance, no deployment overhead, configurable by power users.
  2. Reference-based document passing — SharePoint URL instead of binary content keeps payloads small and secure.
  3. Two-pass matching (Exact → Weighted) — Maximizes automation rate while maintaining accuracy.
  4. UI automation for ERP — Respects ERP governance when no API exists; uses the system's own validation.
  5. Draft/Hold order state — Humans remain in the loop for financial decisions; automation handles data work.
  6. Correlation ID across all systems — Makes debugging and auditing trivial in a multi-system pipeline.

Diagram 1 — End-to-end architecture overview

Blog content image

Diagram 2 — Matching engine decision flow

Blog content image

Diagram 3 — ERP integration flow (Power Automate to Sage)

Blog content image

Diagram 4 — Confidence thresholds & exception handling

Blog content image