---
title: External view update tracking
summary: Tracks when an image file's external (agent/customer-facing) view needs to be, or was, refreshed, using optimistic concurrency on update.
status: draft
owner: <owner>
last_reviewed: 2026-07-30
library: SAIF.Business.Imaging
reference_type: package
operation_id: OP-IMG-03
trigger: Caller creates, retrieves, or updates a clsImageFileExternalViewUpdate instance for a given image file code and key
---

# External view update tracking

This operation records and updates the external-view refresh state for a given image file (identified by `ImageFileCode` and `ImageFileKey`). It is used to know whether a document's externally-visible rendering reflects the latest data or is pending an update. Updates are protected by an optimistic concurrency check on `UPDATE_NUM`.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-IMG-03 |
| **Trigger** | Caller creates a new tracking row via `clsImageFileExternalViewUpdate`, retrieves an existing one by file code/key, or updates it after the external view date changes |
| **Inputs** | `ImageFileCode`, `ImageFileKey`, external view date, and (for update) the current `UpdateNum` |
| **Outputs** | Persisted `IMAGE_FILE_EXT_VIEW_UPDATE` row (insert), a populated instance (retrieve), or an updated row with an incremented `UPDATE_NUM` (update) |
| **Primary components** | `clsImageFileExternalViewUpdate.BeforeInsert`, `clsImageFileExternalViewUpdate.BeforeRetrieve`, `clsImageFileExternalViewUpdate.BeforeUpdate`, `clsImageFileExternalViewUpdate.AfterUpdate` |
| **Entry point** | `Business\SAIF.Business.Imaging\clsImageFileExternalViewUpdate.vb` |

## Steps

1. **Caller provides `ImageFileCode` and `ImageFileKey`** to a new `clsImageFileExternalViewUpdate` instance, along with the external view date to record.
2. **Insert the tracking row.** `BeforeInsert` executes [SQL-006](../sql/SQL-006-saif-business-imaging.md) to insert into [IMAGE_FILE_EXT_VIEW_UPDATE](../database-tables.md#image_file_ext_view_update).
3. **Retrieve an existing tracking row.** `BeforeRetrieve` executes [SQL-027](../sql/SQL-027-saif-business-imaging.md) to load the record by `ImageFileKey` and `ImageFileCode`.
4. **Update the tracking row.** `BeforeUpdate` executes [SQL-035](../sql/SQL-035-saif-business-imaging.md); the WHERE clause requires the row's current `UPDATE_NUM` value in addition to the file key, functioning as an optimistic concurrency check.
5. **Verify the update.** `AfterUpdate` reads the rows-affected result and raises an error message if it is not exactly one row.
   - On failure (0 rows affected — the `UPDATE_NUM` no longer matches): the update is rejected as a concurrency violation, meaning a concurrent update by another session already advanced the row.

## Process flow

The following diagram visualizes the external view update tracking operation's control flow.

```mermaid
flowchart TD
	Start([Caller provides ImageFileCode<br>and ImageFileKey]) --> Which{Which action?}
	Which -->|Create| Insert[BeforeInsert: INSERT row]
	Insert --> DoneI([Tracking row created])
	Which -->|Retrieve| Retrieve[BeforeRetrieve by<br>ImageFileKey + ImageFileCode]
	Retrieve --> DoneR([Tracking row loaded])
	Which -->|Update| Update[BeforeUpdate: UPDATE row<br>WHERE current UPDATE_NUM]
	Update --> Check{AfterUpdate:<br>exactly 1 row?}
	Check -->|No| Conflict([Concurrency violation:<br>error raised])
	Check -->|Yes| DoneU([Tracking row updated])
```

## Failure and edge-case behavior

- `clsImageFileExternalViewUpdate.BeforeUpdate` requires the current `UPDATE_NUM` value in the WHERE clause, so concurrent updates by different sessions to the same file key will cause the second update to affect zero rows.
- `AfterUpdate` raises an error message when the rows-affected count is not exactly one, surfacing the concurrency conflict to the caller rather than silently no-op'ing.

## Related documentation

- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

## Sources

- `Business\SAIF.Business.Imaging\clsImageFileExternalViewUpdate.vb`
