---
title: PolicyDocumentsBatchService
summary: API reference for PolicyDocumentsBatchService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# PolicyDocumentsBatchService

Implements `IPolicyDocumentsBatchService`, running the batch release of pending policy output documents, generating email and task notifications to agencies/producers/marketing reps for newly released documents, reverting agencies whose paperless delivery has no active user, and creating underwriting hold-review tasks. It depends on `IUnitOfWork` for transactional repository access, `IOutputDocumentQueryProvider` for release-date and status lookups, `ITaskFactory` for creating marketing/underwriting tasks, `IUserProfileService` for the current user, `IPolicyOutputDocumentRepository` for held/pending document queries, `IAgencyService` for agency email lists and paperless-reversion candidates, `IEmailService` for sending notification emails, and `INoteService` (injected but not directly invoked in the reviewed code).

## Purpose
- Releases all pending policy output documents whose document date has reached the current release date, recording per-document release details.
- Generates agency, producer, and direct-writer notifications (email and marketing tasks) for documents just released.
- Reverts agencies that have no responsible user back to paper delivery and emails an internal notice for each reversion.
- Creates underwriting tasks for documents held in the Pending Documents queue that need review.

## Context
- Namespace: `SAIF.Services.OutputDocuments`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| PolicyDocumentsBatchService(...) | `public PolicyDocumentsBatchService(IUnitOfWork uow, IOutputDocumentQueryProvider queryProvider, ITaskFactory task, IUserProfileService profileService, IPolicyOutputDocumentRepository policyOutputDocumentRepository, IAgencyService agencyService, IEmailService emailService, INoteService noteService)` | Validates every collaborator is non-null via `Enforce.ArgumentNotNull` and wires them in for use by the batch operations. |
| GetDocumentDate | `public DateTime GetDocumentDate()` | Returns the current output-document processing/release date from the query provider. |
| ReleaseDocuments | `public DocumentReleaseResult ReleaseDocuments(bool reportOnly = false)` | Within a transaction, marks all pending documents due for release as released, builds a `DocumentReleaseResult` describing each released document, generates notifications for them, and either commits (persisting the release) or rolls back when `reportOnly` is true; rolls back and rethrows on any error. |
| GenerateAllExternalAgencyNotifications | `public IList<DocumentReleaseResult.ReleaseNotification> GenerateAllExternalAgencyNotifications(DateTime releaseDate, string fromEmailAddress, Boolean reportOnly)` | Finds released, agency-inbox-viewable, unviewed documents for `releaseDate`, then emails and records notifications grouped by agency and by producer (excluding agency/producer duplicates); returns the combined notification list. |
| RevertUserlessAgencies(toEmail, reportOnly) | `public AgencyRevertResults RevertUserlessAgencies(string toEmail, bool reportOnly)` | Reverts userless agencies to paper delivery using `"SYSTEM"` as the acting user, delegating to the overload that accepts an explicit calling user. |
| RevertUserlessAgencies(toEmail, reportOnly, callingUser) | `public AgencyRevertResults RevertUserlessAgencies(string toEmail, bool reportOnly, string callingUser)` | For each agency flagged as reverting, unless `reportOnly`, turns off its paperless flag and pending paperless request and emails an internal notice; always returns the list of agencies that were (or would be) reverted with descriptive text. |
| SendInternalRevertingAgencyEmail | `public void SendInternalRevertingAgencyEmail(string emailMessage, string toEmailAddress)` | Sends a fixed-subject internal HTML email (from a hard-coded system address) reporting an agency paperless reversion, via `_emailService`. |
| GenerateHoldTasks | `public DocumentHoldNotificationResult GenerateHoldTasks(bool reportOnly = false)` | Within a transaction, finds held documents awaiting task notification, groups them by policy/document date/task user, creates an underwriting task per group via `ITaskFactory.CreateUnderwritingTask`, and returns a result describing documents processed and tasks created. |

## Behavioral notes
- `ReleaseDocuments` and `GenerateHoldTasks` both wrap their multi-step work in `unitOfWork.Begin()`/`Commit()`/`Rollback()`, and `ReleaseDocuments` additionally allows a "dry run" via the `reportOnly` flag that always rolls back after computing results.
- Notification generation groups documents by agency, by producer, and (for direct-writer/self-serviced policies) by policy/notification-text combination, truncating any resulting task text to 4000 characters before creating a marketing task.
- Direct-writer notifications are only generated when the SAIF house agency (`Agency.SaifAgencyId`) is paperless for policyholder-copy documents, and only for policies in a "regional" office (i.e. not the service-center or assigned-risk office).
- Emails sent through `SendAgentEmailDocumentNotification` are suppressed (constructed but not sent) whenever `reportOnly` is true.

## Sources
- Services/SAIF.Services/OutputDocuments/PolicyDocumentsBatchService.cs
