---
title: Aggregate active offices across agencies
summary: Build one detached office collection from the active offices of many agencies.
status: draft
owner: Technical Writer
last_reviewed: 2026-07-31
library: SAIF.Business.Policy.Agency
reference_type: package
operation_id: OP-014
trigger: A caller requests all active offices across an agency collection.
---

# Aggregate active offices across agencies

This operation walks an agency collection, loads each agency's office rows as needed, and clones the active offices into one detached result collection.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-014 |
| **Trigger** | A caller invokes `clsAgencyCollection.ActiveAgencyOffices(inDate)`. |
| **Inputs** | `clsAgencyCollection`, as-of date |
| **Outputs** | `clsAgencyOfficeCollection` |
| **Primary components** | `clsAgencyCollection.ActiveAgencyOffices`, `clsAgency.Offices`, `clsAgencyOfficeCollection.AddClone` |
| **Entry point** | `Business\SAIF.Business.Policy.Agency\clsAgencyCollection.vb`, `Business\SAIF.Business.Policy.Agency\clsAgencyOfficeCollection.vb` |

## Steps
1. Iterate each agency in the source collection.
2. Ensure that agency's office collection is loaded, lazily retrieving it with [SQL-006](../sql/SQL-006-retrieve-agency-offices-for-an-agency.md) from [AGENT](../database-tables.md#agent) when necessary.
3. Filter each office collection to rows active on the requested date ([BR-008](../business-rules.md#br-008-active-status-uses-effective-and-expiration-windows)).
4. Clone each active office into the aggregated result collection rather than reusing the original object instance ([BR-022](../business-rules.md#br-022-active-office-aggregation-clones-offices-without-data-portal-context)).
5. Return the detached office collection after all agencies have been processed.

## Process flow

The following diagram visualizes active-office aggregation.

```mermaid
flowchart TD
  Start([ActiveAgencyOffices]) --> Loop[Iterate agencies]
  Loop --> Load[Ensure offices loaded]
  Load --> Filter[Filter active offices]
  Filter --> Clone[Clone office into result]
  Clone --> More{More agencies?}
  More -->|Yes| Loop
  More -->|No| End([Detached office collection returned])
```

## Failure and edge-case behavior
- Agencies with no active offices contribute nothing to the aggregated result.
- The operation may still trigger one office query per agency when office collections were not preloaded.

## Related documentation
- [Index](../index.md)
- [Overview](../overview.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Database tables](../database-tables.md)
- [SQL catalog](../sql/index.md)
- [API reference](../api/index.md)

## Sources
- `Business\SAIF.Business.Policy.Agency\clsAgencyCollection.vb`
- `Business\SAIF.Business.Policy.Agency\clsAgencyOfficeCollection.vb`
