# Reassignment: reacting to it with an event

An open approval changes hands in four ways: a user hands it to somebody else in the **Reassign Approval** dialog, an escalation step passes it on, Business Central hands it to the substitute on record, or an administrator gives up a claimed entry. Partners and customers with their own development can react to every one of these — with an integration event that is raised after the handover and says who held the approval before and who holds it now.

This page is the developer contract: the event, its parameters, which way produces which values, and an example.

## Typical use

A company also tracks its approvals in a ticket system of its own. When an approval moves, the ticket should follow the new assignee, so that nobody has to look in two systems. A subscriber writes every handover into a table of its own and makes the connection from there; the workflow itself is untouched.

## The event

Publisher: codeunit `DXP AWF Approval Entry Helper`, integration event `OnAfterApprovalReassigned`. It is raised only after the handover has succeeded — so a subscriber may rely on the new approval entries existing, and on an entry still being open for the record.

<table id="bkmrk-parametermeaning-ins"><tbody><tr><th>Parameter</th><th>Meaning</th></tr><tr><td><code>InstanceID&#58; Guid</code></td><td>The workflow instance the approval belongs to.</td></tr><tr><td><code>RecordID&#58; RecordId</code></td><td>The record whose approval changed hands — a document or one of its lines.</td></tr><tr><td><code>AssignmentSource&#58; Enum &#34;DXP AWF Assignment Source&#34;</code></td><td>What reassigned it: **Reassignment** when a user handed it on, **Escalation** for an escalation's reassign step. Blank for a delegation.</td></tr><tr><td><code>SubstitutionReason&#58; Enum &#34;DXP AWF Substitution Reason&#34;</code></td><td>Why somebody else holds it: **Delegation**, **Escalation** or **Administrator**. Blank for a reassignment.</td></tr><tr><td><code>PreviousAssigneeType&#58; Enum &#34;DXP AWF Assignee Type&#34;</code></td><td>Whom the approval was assigned to before. Blank on entries created before version 1.16 — those do not know their type.</td></tr><tr><td><code>PreviousAssigneeCode&#58; Code&#91;50&#93;</code></td><td>The previous approver, workflow user group or external approver.</td></tr><tr><td><code>NewAssigneeType&#58; Enum &#34;DXP AWF Assignee Type&#34;</code></td><td>Whom it is assigned to now.</td></tr><tr><td><code>NewAssigneeCode&#58; Code&#91;50&#93;</code></td><td>The new approver, workflow user group or external approver.</td></tr><tr><td><code>Reason&#58; Text</code></td><td>The reason the user gave. Empty on the ways that ask for none.</td></tr></tbody></table>

<p class="callout info">The two enums are the ones the approval entry itself records: **Assignment Source** and **Substitution Reason**. A reassignment names an assignment source and leaves the substitution reason blank; a delegation does the opposite — it changes who holds an entry, not whom the stage assigned it to.</p>

## Which way produces which values

<table id="bkmrk-wayassignment-source"><tbody><tr><th>Way</th><th>Assignment Source</th><th>Substitution Reason</th><th>Reason</th></tr><tr><td>**Reassign Approval** — the dialog, the **Related approvals** FactBox and the line subforms</td><td>Reassignment</td><td>blank</td><td>the user's mandatory entry</td></tr><tr><td>**Escalation step "Reassign"**</td><td>Escalation</td><td>blank</td><td>generated, naming the step no. and the days overdue</td></tr><tr><td>**Escalation step "Delegate"**</td><td>blank</td><td>Escalation</td><td>empty</td></tr><tr><td>**Delegation to the substitute** — Business Central's own way</td><td>blank</td><td>Delegation</td><td>empty</td></tr><tr><td>**Administrator gives up a claim**</td><td>blank</td><td>Administrator</td><td>empty</td></tr></tbody></table>

A delegation always goes to a named user, never to a group: `PreviousAssigneeType` and `NewAssigneeType` are both **Approver** there.

## Example: recording every handover

```
codeunit 50112 "MY AWF Reassignment Log"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP AWF Approval Entry Helper", 'OnAfterApprovalReassigned', '', false, false)]
    local procedure LogHandover(InstanceID: Guid; RecordID: RecordId; AssignmentSource: Enum "DXP AWF Assignment Source"; SubstitutionReason: Enum "DXP AWF Substitution Reason"; PreviousAssigneeType: Enum "DXP AWF Assignee Type"; PreviousAssigneeCode: Code[50]; NewAssigneeType: Enum "DXP AWF Assignee Type"; NewAssigneeCode: Code[50]; Reason: Text)
    var
        Handover: Record "MY AWF Handover";
    begin
        // Only purchase documents are of interest here.
        if RecordID.TableNo() <> Database::"Purchase Header" then
            exit;

        Handover.Init();
        Handover."Instance ID" := InstanceID;
        Handover."Record ID" := RecordID;
        Handover."From Type" := PreviousAssigneeType;
        Handover."From Code" := PreviousAssigneeCode;
        Handover."To Type" := NewAssigneeType;
        Handover."To Code" := NewAssigneeCode;
        // A delegation gives no reason - the substitution reason says it instead.
        if Reason = '' then
            Handover.Reason := Format(SubstitutionReason)
        else
            Handover.Reason := CopyStr(Reason, 1, MaxStrLen(Handover.Reason));
        Handover."Logged At" := CurrentDateTime();
        Handover.Insert(true);
    end;
}
```

## What the event does not do

- **It cannot be cancelled.** It has no `IsHandled` parameter and is raised only once the handover has already happened.
- **Advanced Workflow approvals only.** Entries without a workflow instance — from a BC standard workflow, for example — do not raise it.
- **No event without a handover.** If the record has no open Advanced Workflow approval, nothing happens and the event stays out.
- An error in a subscriber does not undo the handover; it leaves an error message with the user who triggered it.
- The **Audit Trail** records the handover anyway. The event is meant for reacting to it, not as a replacement for it.

## Related pages

- **Module: Approval Reassignment**
- **Proposed assignee: setting it with an event** — deciding what the dialog proposes before the user confirms
- **Module: Escalation Engine** — the "Reassign" and "Delegate" steps