Stage 9 of 17
3 Power Automate flows: renewal reminders with duplicate prevention, availability threshold notifications, and automatic status transitions. Full build steps and calculation explanations for each.
Trigger
Scheduled — daily at 07:00
Purpose
Send renewal reminder emails at 90, 60, and 30 days before RenewalDate
Duplicate prevention
ReminderSentFlags field on Agreements list
Recipients
Agreement Owner + Tom Reeves
Why Daily at 07:00?
Trigger
Recurrence. Frequency: Day. Interval: 1. Start time: 07:00 UTC. Note: adjust for BST/GMT if needed — see the timezone guidance in DTOD-012 Stage 9.
Get items — Agreements
SharePoint Get items. Site: Software Licence Management. List: Agreements. Filter query: Status eq 'Active' or Status eq 'Pending Renewal'. This limits the flow to agreements that are still active or already flagged for renewal.
Apply to each — agreement
Loop over each agreement returned by Get items.
Calculate DaysToRenewal
Compose action: div(sub(ticks(items('Apply_to_each')?['RenewalDate']), ticks(utcNow())), 864000000000). This calculates the number of days between now and the RenewalDate using ticks (100-nanosecond intervals). 864000000000 ticks = 1 day.
For each milestone (90, 60, 30) — Condition
Condition: DaysToRenewal <= milestone AND DaysToRenewal >= 0 AND milestone not in ReminderSentFlags. Use: not(contains(items('Apply_to_each')?['ReminderSentFlags'], '90')) for the 90-day check.
Send email (if condition is true)
Send an email to the Owner's email address and tom.reeves@contoso.com. Subject: "Licence renewal reminder: [Product] — [milestone] days remaining". Body: Include product name, supplier, RenewalDate, QuantityPurchased, AnnualisedCost, and a link to the SharePoint list.
Update ReminderSentFlags (if condition is true)
SharePoint Update item. Set ReminderSentFlags to: if(empty(items('Apply_to_each')?['ReminderSentFlags']), '90', concat(items('Apply_to_each')?['ReminderSentFlags'], '|90')). This appends the milestone to the existing flags, producing e.g. "90|60" after the second reminder.
Update Status to Pending Renewal (if condition is true)
SharePoint Update item. Set Status to "Pending Renewal". This triggers the visual indicator in the Power App.
The Ticks Calculation Explained
ReminderSentFlags Leading Pipe Bug
Trigger
When an item is created or modified in the Allocations list
Purpose
Notify when QuantityAvailable falls to or below the threshold, or goes negative (over-allocation)
Recipients
Agreement Owner + Tom Reeves
Two alert levels
Low availability (amber) and Over-Allocated (red)
Trigger
SharePoint — When an item is created or modified. Site: Software Licence Management. List: Allocations.
Get the Agreement record
SharePoint Get item. Site: Software Licence Management. List: Agreements. ID: triggerOutputs()?['body/Agreement/Id']. This retrieves the full agreement record linked to the allocation.
Count active allocations
SharePoint Get items. List: Allocations. Filter query: Agreement/Id eq [AgreementID] and Status eq 'Active'. Then use length(body('Get_items')?['value']) to get the count.
Calculate QuantityAvailable
Compose: sub(body('Get_item')?['QuantityPurchased'], length(body('Get_items')?['value'])). Result: QuantityPurchased minus the count of active allocations.
Calculate threshold
Compose: if(empty(body('Get_item')?['AvailabilityThreshold']), max(1, int(mul(body('Get_item')?['QuantityPurchased'], 0.1))), body('Get_item')?['AvailabilityThreshold']). This uses the AvailabilityThreshold field if set, otherwise calculates 10% of QuantityPurchased with a minimum of 1.
Condition: Over-Allocated
If QuantityAvailable < 0: Send a high-urgency email to Tom Reeves. Subject: "URGENT: Over-Allocated licence — [Product]". Body: Include product, QuantityPurchased, QuantityAllocated, overage amount. This is a compliance risk.
Condition: Low Availability
Else if QuantityAvailable <= threshold AND QuantityAvailable >= 0: Send a standard notification to Owner and Tom Reeves. Subject: "Low licence availability: [Product] — [QuantityAvailable] remaining". Body: Include product, QuantityPurchased, QuantityAllocated, QuantityAvailable, threshold.
Threshold Calculation Examples
Trigger
Recurrence. Frequency: Day. Interval: 1. Start time: 06:00 UTC (runs before DToDLab013-RenewalReminder at 07:00).
Get items — Active agreements
SharePoint Get items. List: Agreements. Filter query: Status eq 'Active'.
Apply to each
Loop over each active agreement.
Calculate DaysToRenewal
Same ticks calculation as Flow 1.
Condition: DaysToRenewal ≤ 90
If DaysToRenewal ≤ 90 AND DaysToRenewal ≥ 0: Update Status to "Pending Renewal". This ensures the Renewals screen in the Power App shows the agreement with the correct status before the reminder email is sent.
Why Run StatusTransition Before RenewalReminder?
Need more help with the concepts?
Visit DosToDigital for guides, templates, and deeper explanations.