Stage 9 of 17

Stage 9 of 17

Automate

3 Power Automate flows: renewal reminders with duplicate prevention, availability threshold notifications, and automatic status transitions. Full build steps and calculation explanations for each.

Flow 1 — DToDLab013-RenewalReminder

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?

The flow runs daily so it catches agreements that enter a reminder window overnight. Running at 07:00 means reminders arrive in inboxes at the start of the working day, when they are most likely to be acted on. The ReminderSentFlags field prevents the same reminder being sent more than once per milestone.
1

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.

2

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.

3

Apply to each — agreement

Loop over each agreement returned by Get items.

4

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.

5

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.

6

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.

7

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.

8

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

Power Automate does not have a native DateDiff function. The ticks() function returns the number of 100-nanosecond intervals since 1 January 0001. To calculate days between two dates: subtract the ticks of the earlier date from the ticks of the later date, then divide by 864000000000 (the number of ticks in one day: 24 hours × 60 minutes × 60 seconds × 10,000,000 ticks per second = 864,000,000,000). The result is the number of days as a decimal — use int() to round down.

ReminderSentFlags Leading Pipe Bug

The same leading pipe bug from DTOD-012 applies here. If ReminderSentFlags is blank and you use concat(existingValue, '|', '90'), you get "|90" instead of "90". Always use the conditional expression: if(empty(existingValue), '90', concat(existingValue, '|90')). This produces "90" when blank and "90|60" when appending.

Flow 2 — DToDLab013-AvailabilityAlert

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)

1

Trigger

SharePoint — When an item is created or modified. Site: Software Licence Management. List: Allocations.

2

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.

3

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.

4

Calculate QuantityAvailable

Compose: sub(body('Get_item')?['QuantityPurchased'], length(body('Get_items')?['value'])). Result: QuantityPurchased minus the count of active allocations.

5

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.

6

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.

7

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

AGR-001 (300 licences): threshold = max(1, int(300 × 0.1)) = max(1, 30) = 30. Alert fires when QuantityAvailable ≤ 30. AGR-010 (15 licences): threshold = max(1, int(15 × 0.1)) = max(1, 1) = 1. Alert fires when QuantityAvailable ≤ 1. AGR-004 (10 licences, AvailabilityThreshold = 3): threshold = 3 (override). Alert fires when QuantityAvailable ≤ 3.

Flow 3 — DToDLab013-StatusTransition

1

Trigger

Recurrence. Frequency: Day. Interval: 1. Start time: 06:00 UTC (runs before DToDLab013-RenewalReminder at 07:00).

2

Get items — Active agreements

SharePoint Get items. List: Agreements. Filter query: Status eq 'Active'.

3

Apply to each

Loop over each active agreement.

4

Calculate DaysToRenewal

Same ticks calculation as Flow 1.

5

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?

DToDLab013-StatusTransition runs at 06:00 and DToDLab013-RenewalReminder runs at 07:00. This ensures that when the reminder flow runs, the agreement status has already been updated to "Pending Renewal". The reminder email can then accurately state the current status. If they ran in the wrong order, the reminder would be sent before the status was updated.

Stage Complete — What You Now Have

  • ✓DToDLab013-RenewalReminder: 3 milestones (90/60/30 days), ReminderSentFlags duplicate prevention, leading pipe bug fix
  • ✓DToDLab013-AvailabilityAlert: two alert levels (low availability and over-allocation), configurable threshold, 10% default with minimum 1
  • ✓DToDLab013-StatusTransition: automatic Active → Pending Renewal at 90 days, runs before RenewalReminder
  • ✓Ticks calculation explained for DaysToRenewal
  • ✓Threshold calculation explained with examples from sample data
NextSecure

Need more help with the concepts?

Visit DosToDigital for guides, templates, and deeper explanations.

DosToDigital
DToD Labs

Learn it. Build it. Make it work.

A DosToDigital Project

About DToD Labs

Practical technology learning for Microsoft 365 and Power Platform. Build real business solutions from real business problems.

Learn the concepts at DosToDigital. Put them into practice at DToD Labs.

DToD Labs provides practical learning projects for educational purposes. Microsoft services, interfaces, licensing and product capabilities change over time. Always check current Microsoft documentation and licensing before implementing a solution in a production environment. All organisations, business scenarios and data used in DToD Labs are fictional. Learners should not use confidential employer, customer or personal information when following DToD Labs exercises.

© 2026 DToD Labs — A DosToDigital Project