Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 38 ยท Projects and Practice

Project: Invoices from Email to a Desktop Application

Combine a cloud flow and a desktop flow: collect invoice emails, extract fields, validate and de-duplicate them, enter them in a legacy application with RPA, and report exceptions.

Many companies still run an accounting program that has no API. Suppliers send invoices as email attachments, and someone retypes them. This project automates that with the two halves of Power Automate: a cloud flow that collects and checks the invoices, and a desktop flow that types them into the legacy application. You will practice the cloud/desktop split, inputs and outputs, idempotency, batching and exception handling.

Neither the cloud designer nor Windows RPA runs on this site. The build steps are described in words, and the logic (parsing, validation, de-duplication, batching) is modeled in runnable JavaScript stand-ins, so you can test the rules before building.

Requirements

  1. Watch the shared mailbox invoices@ for new emails with attachments.
  2. For each PDF or text invoice, extract: supplier, invoice number, date, net amount, tax and total.
  3. Validate the numbers (net + tax = total) and reject duplicates (same supplier and number).
  4. Enter valid invoices in the legacy application "LedgerPro" through its screens, and capture the posting number it displays.
  5. Move processed emails to a Done folder, problems to Exceptions, and send a daily summary.
  6. Be restartable: a crash in the middle must not enter an invoice twice.

Architecture

flowchart TB
    M["Shared mailbox"] --> CF["Cloud flow: When a new email arrives (V3)"]
    CF --> X["Extract + validate<br/>(AI Builder or parsing rules)"]
    X -->|"problem"| E["Exceptions folder + alert"]
    X -->|"valid"| DUP{"Already in log?"}
    DUP -->|"yes"| S["Skip + move to Done"]
    DUP -->|"no"| DF["Run desktop flow<br/>EnterInvoice"]
    DF -->|"posting number"| L["Write log row + move to Done"]
    DF -->|"error"| E

The cloud flow does the thinking; the desktop flow does the typing.

The cloud flow, step by step

Trigger: Outlook or Office 365 When a new email arrives in a shared mailbox (V2), with Only with attachments set to Yes and Include attachments Yes. Add a trigger condition if you only want emails from known supplier domains.

Loop: Apply to each attachment (loops); filter by name first with Filter array so only .pdf and .txt attachments are processed.

Extract: two common routes:

  • AI Builder invoice processing model (a premium feature; extracts supplier, number, amounts from PDFs). Treat its confidence scores as inputs to a decision: accept above a threshold, send low-confidence items to a person.
  • Rules for structured text (CSV or plain-text invoices) using expressions such as split(), indexOf() and substring(), or an Office Script / Azure Function for a regular expression.

Validate and de-duplicate: a Compose checks the arithmetic; Get items with a Filter Query on Supplier eq '...' and InvoiceNumber eq '...' against the InvoiceLog list; if the count is above zero, skip. This is the idempotency pattern.

Call the desktop flow: action Run a flow built with Power Automate for desktop, with the machine connection and run mode Unattended for overnight runs or Attended while a person is working (run modes). Inputs: Supplier, InvoiceNumber, InvoiceDate, Net, Tax, Total. Output: PostingNumber and Status.

After the call: if Status is Posted, add the log row and move the email to Done. Wrap the desktop call in a Try scope with a Catch that moves the email to Exceptions and alerts the team (try/catch). Set a timeout on the call, such as PT10M.

Batch or per-invoice?

One desktop run per invoice is simple but starts the application again each time. For nightly volume it is better to collect the valid invoices into a file or table during the day and make one desktop run that loops over the batch, returning a result per row (machines and queues). The stand-in below shows the difference.

The desktop flow EnterInvoice

Described in words, with the techniques from chapter 6:

  1. Input variables: Supplier, InvoiceNumber, InvoiceDate, Net, Tax, Total (all text, because they come through the connector). Output variables: PostingNumber, Status, ErrorText.
  2. Start state: if LedgerPro is running, close it; Run application LedgerPro; Wait for window content (title contains "LedgerPro") with a 60 second timeout.
  3. Log in only if the login window appears, using a sensitive input or a credential vault, not typed text.
  4. Navigate: click the UI element Menu > Purchases > New invoice; wait for the form.
  5. Populate fields with Populate text field in window for each UI element; use Set drop-down list value for the supplier. Check the supplier exists; if the lookup shows "not found", set Status = NoSupplier, and end the subflow.
  6. Save: click Save; wait for the confirmation window; read its text with Get details of a UI element in window into %ConfirmText%; parse the posting number with Parse text and a pattern like P-\d{6}.
  7. Error handling: wrap the sequence in On block error that captures %LastError% into ErrorText, takes a screenshot into a log folder, closes the application and sets Status = Failed.
  8. Finish: close LedgerPro and return the outputs.

Keep the selectors robust (selectors): Ids and names first, no coordinates, conditional waits everywhere.

Model the extraction and checks

JS Stand-in: parse, validate and de-duplicate invoices

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Model batch versus single runs

JS Stand-in: start-up cost of single versus batch desktop runs

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Testing and rollout

  1. Test the cloud flow with sample emails, with the desktop call replaced by a Compose, and check the log and folders.
  2. Test the desktop flow alone with each input case: normal, unknown supplier, a locked screen, the application not running.
  3. Test them together in attended mode while you watch, then switch to unattended.
  4. Test restart safety: stop the flow after the desktop run but before the log row, and run again; the application's own duplicate check (or a look-up before saving) must prevent a double posting.
  5. Add monitoring: failure alerts, the daily summary, and a heartbeat check (monitoring).
  6. Move it to a solution with environment variables for mailbox, folder names and tolerance; check licensing for AI Builder, premium connectors and unattended RPA (licensing).

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Where should the arithmetic check and duplicate lookup happen in this design?

    Cheap checks belong before the fragile, slow screen automation.
  2. 2. Why return PostingNumber and Status as outputs of the desktop flow?

    The cloud flow needs the outcome to log, move the email and alert.
  3. 3. For 100 invoices overnight, which is usually more efficient?

    One start-up cost is shared by all invoices.

Summary

  • Split the work: cloud flow for triggers, extraction, validation and de-duplication; desktop flow for the screen-only step.
  • Pass small values in, return a status and a posting number out, and handle every failure with logging, screenshots and cleanup.
  • Make restarts safe with a log and lookups, and prefer batches for volume.
  • Package, secure and monitor the solution like any production system.

Next: Practice Scenarios and Design Exercises