Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 38 ยท Projects and Practice

Project: An Expense Approval Process

Design and build a complete expense approval flow: form trigger, validation, routing by amount, approvals with escalation, error handling and logging, with a runnable model of the rules.

This project ties together most of what chapters 5 to 8 taught: branching, approvals, loops, run after, retries, patterns and governance. You will design a flow for a realistic process, expense approval, in enough detail to build it in the designer. The product cannot run on this site, so the build steps are described precisely in words, and the business rules are modeled as runnable JavaScript so you can test the logic of the design before you click anything.

The requirements

Employees submit an expense request with: employee email, date, category (Travel, Meals, Equipment, Other), amount, currency, description and a receipt file. The process must:

  1. Reject requests that are incomplete or obviously invalid (negative amount, future date, no receipt over 25 in the local currency).
  2. Route by amount: up to 100 needs the manager; over 100 up to 1,000 the manager and then the department head; over 1,000 also finance.
  3. Treat the category Equipment as always needing finance review.
  4. Remind approvers after 2 days; escalate to a backup after 4; expire after 7 days.
  5. Notify the employee of the result with the approver's comment.
  6. Record every request in a log list; alert the flow owners on failure.
  7. Be safe to run twice for the same request (no duplicate payments).

The data model

A SharePoint list or Dataverse table Expenses with columns: Title, Employee (email), Amount (number), Currency, Category (choice), Receipt (attachment), Status (choice: Submitted, Invalid, Pending, Approved, Rejected, Expired), Approvers (text log), ProcessedOn (date). A second list ExpenseLog stores one row per run.

Architecture

flowchart TB
    T["Trigger: item created"] --> V["Scope: Validate"]
    V -->|"invalid"| R1["Status Invalid + notify + Terminate"]
    V -->|"valid"| A["Scope: Approvals<br/>route by amount and category"]
    A --> D{"Final decision"}
    D -->|"Approved"| P["Mark Approved + queue payment"]
    D -->|"Rejected or expired"| R2["Mark + notify with reason"]
    P --> L["Scope: Log"]
    R2 --> L
    A -.->|"failure"| C["Scope: Catch<br/>alert owners"]

Validate, approve, finish, log; and a Catch alongside, built with the scope pattern from run after.

Step by step

1. Trigger. Use When an item is created (SharePoint) for the Expenses list. In the trigger's Settings add a trigger condition so only Submitted items start a run, and set trigger concurrency control to a degree that your downstream systems can handle (flow patterns).

2. Validate scope. Compute checks in a Compose action named Problems that builds an array of messages with an expression such as if(less(float(triggerOutputs()?['body/Amount']), 0), 'Amount is negative', null). Use Filter array to drop the empty entries; if length() of the result is greater than 0, update Status to Invalid, email the employee the list, and Terminate with status Succeeded (an invalid form is a normal business outcome, not a flow failure).

3. Idempotency. Before routing, read Status. If it is anything other than Submitted, Terminate (Succeeded), so a re-run cannot pay twice (idempotent processing). Set Status to Pending immediately to claim the item.

4. Approvals scope. Use Start and wait for an approval (approval types) of type Approve/Reject - First to respond for the manager, with a Timeout of P7D. Look the manager up with the Office 365 Users connector (Get manager). In the Details field show employee, amount, category, description and a link to the item. Nest the next approvals in the If yes branch only when the routing function says they are needed: department head, then finance. Keep the routing decision in one Compose that outputs an ordered array of approver roles, then loop over it sequentially (Apply to each) and stop the loop on the first rejection by setting a variable and checking it.

5. Reminders and escalation. Use the two-action form (Create an approval + Wait for an approval) with a parallel branch: one branch waits for the approval; the other runs a Delay of two days, then posts a reminder, then delays two more days and reassigns to the backup. When the approval finishes, the flow continues. Cancelling the extra branch is not needed because the join waits for both; give the delay branch a Do until that exits as soon as the approval has an outcome (see Do until).

6. Finish. Update Status, Approvers and ProcessedOn. Send the employee a message built from the Responses array, including comments. For Approved, call a child flow that creates the payment request (HTTP to the finance API with retries and an idempotency key built from the item id; see retry policies).

7. Log scope and Catch. Add a log row with run id (workflow()?['run']?['name']), item id, final status. The Catch scope runs after the main scopes fail or time out and posts to the owners' Teams channel with the error from result(), then Terminates as Failed.

8. Package. Build it inside a solution with connection references and environment variables for the list URLs, approval limits (100, 1,000), reminder days and the finance mailbox (environments and solutions). Check the connectors against your DLP policy (governance). All connectors here (SharePoint, Approvals, Office 365 Users, Teams, Outlook) are standard; the HTTP call to finance is premium.

Model the rules first

Before building, check that the routing and validation behave as the requirements say. The program below is a stand-in for the Compose expressions and the Condition logic.

JS Stand-in: validation and routing rules

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

No output.

Model the timing

The reminder and escalation rules are easy to get wrong. This stand-in prints what happens on each day for a request nobody answers.

JS Stand-in: reminder, escalation and expiry

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

No output.

Testing checklist

  1. Submit one request of each kind from the model (valid small, mid, equipment, large, no receipt, negative).
  2. Reject at each approval level and check the message and status.
  3. Run the same item twice; confirm there is one payment.
  4. Break the finance API address on purpose; confirm retries, then the Catch alert and a Failed run.
  5. Let a test approval expire with a short timeout (PT2M) to prove the timeout path.
  6. Export the solution, import it into a second environment, map the connections, run again.

Extensions

  • Add an adaptive card in Teams for approval and keep email as a fallback.
  • Add a monthly summary flow that totals expenses by department and category with Filter array and Select.
  • Use delegation: a vacation list that routes a manager's approvals to a delegate.
  • Add currency conversion via a custom connector and store the converted amount.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Why does the validation scope end with Terminate set to Succeeded for an invalid form?

    Reserve Failed runs for technical errors so run history stays meaningful.
  2. 2. How does the design stay safe if the flow runs twice for the same expense?

    An existing non-Submitted status makes a repeat run stop early.
  3. 3. Where should the approval limits (100 and 1,000) live?

    Environment variables let each environment set its own values without editing logic.

Summary

  • A real process combines validation, routing, approvals with timers, notifications, logging and error handling.
  • Model the business rules as plain functions first; then build the same logic with Compose, Condition and Switch.
  • Make the flow idempotent, package it in a solution, and test every path, including timeouts and failures.

Next: Project: Invoices from Email to a Desktop Application