Overdue Invoice Teams Alert
Scheduled flow that queries SQL for invoices past their due date and posts an alert to a Teams channel with the overdue count and total amount.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
Scheduled daily flow that queries a SQL Server database for invoices past their due date, aggregates the overdue count and total amount, and posts a styled alert to a Microsoft Teams channel if any overdue invoices exist.
Use Case
Finance and Operations teams need proactive visibility into unpaid invoices that have exceeded their due date. This flow automates the daily check, eliminating the need for manual SQL queries or report refreshes. The Teams alert ensures the right people see overdue invoice summaries without logging into the database.
Flow Architecture
Recurrence Daily Check
RecurrenceFires once per day on schedule (daily at 8:00 AM Eastern by default).
Initialize varSqlServerName
Initialize variableLoads the SQL Server hostname from the flowlibs_SqlServerName environment variable.
Initialize varSqlDatabaseName
Initialize variableLoads the target database name from the flowlibs_SqlDatabaseName environment variable.
Initialize varInvoiceTableName
Initialize variableLoads the fully qualified invoice table name from the flowlibs_InvoiceTableName environment variable.
Initialize varOverdueThresholdDays
Initialize variableLoads the days-past-due threshold from the flowlibs_OverdueThresholdDays environment variable (0 = any past-due).
Initialize varTeamsGroupId
Initialize variableLoads the Microsoft Teams team (group) GUID from the flowlibs_TeamsGroupId environment variable.
Initialize varTeamsChannelId
Initialize variableLoads the target Teams channel ID from the flowlibs_TeamsChannelId environment variable.
Query Overdue Invoice Summary
Execute a SQL query (V2)Runs a native SQL aggregate: SELECT COUNT(*) AS OverdueCount, ISNULL(SUM(InvoiceAmount), 0) AS TotalOverdueAmount FROM {table} WHERE DueDate < DATEADD(DAY, -{threshold}, GETDATE()) AND PaymentStatus = 'Unpaid'.
Parse Query Results
Parse JSONExtracts OverdueCount and TotalOverdueAmount from the SQL result set.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SqlServerName | String | your-server.database.windows.net | SQL Server hostname (e.g. your Azure SQL or on-prem server endpoint). |
| flowlibs_SqlDatabaseName | String | FlowLibsDemoDB | Target database name containing the invoices table. |
| flowlibs_InvoiceTableName | String | [dbo].[Invoices] | Fully qualified SQL table name for invoices. |
| flowlibs_OverdueThresholdDays | String | 0 | Days past due date before flagging (0 = any past-due; set to 7 to only alert 7+ days overdue). |
| flowlibs_TeamsGroupId | String | <configure> | Microsoft Teams team (group) GUID where the alert is posted. |
| flowlibs_TeamsChannelId | String | <configure> | Target Teams channel ID inside the configured group. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| SQL Server | shared_sql | ExecutePassThroughNativeQuery_V2 (Executes the overdue-invoice aggregate query) |
| Microsoft Teams | shared_teams | PostMessageToChannelV3 (Posts the styled overdue alert) |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Connect your SQL Server
- Update the SQL Server connection with your server credentials, then set flowlibs_SqlServerName and flowlibs_SqlDatabaseName to point at your database.
- Create or map the Invoices table
- The flow expects a table with at minimum InvoiceAmount (decimal/money), DueDate (date/datetime), and PaymentStatus (varchar, with 'Unpaid' marking overdue). Adjust the SQL in the Query Overdue Invoice Summary action if your column names differ.
- Configure the Teams destination
- Set flowlibs_TeamsGroupId to your team's Group ID and flowlibs_TeamsChannelId to the target channel where overdue alerts should be posted.
- Adjust the overdue threshold
- Set flowlibs_OverdueThresholdDays to control sensitivity (e.g. 7 to only alert on invoices 7+ days past due).
- Turn on the flow
- Once connections are authorized and env vars configured, toggle the flow to On — it will run daily on the recurrence schedule.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Dynamic SQL query
Builds the parameterized aggregate query at runtime using the table-name and threshold env vars.
EXPR.02Currency formatting
Formats the total overdue amount as a comma-separated value with two decimal places for the Teams message.
EXPR.03Report timestamp (UTC)
Stamps the alert with the UTC time the flow generated the summary.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.