# Proposed assignee: setting it with an event

The dialogs **Reassign Approval**, **Reject Related Approval** and **Send Back Line** ask for a new assignee and propose one when they open. Without a setting that is the type the approval is currently assigned to, otherwise **Approver**; **Default Assignee Type** in the **AWF Setup** sets a fixed type. Partners and customers with their own development can go further and decide the proposal with an integration event — per dialog and per document, with a particular user or group if they like.

This page is the developer contract: the event, its parameters, the order in which the proposal comes about, and an example.

## Typical use

Purchase documents are almost always handed to the purchasing group, sales documents to a particular person. A subscriber proposes the **Workflow User Group** PURCHASING for purchase documents and their lines; the user only has to enter the reason.

## The event

Publisher: codeunit `DXP AWF Assignee Defaults`, integration event `OnAfterGetDefaultAssignee`. It is raised when one of the three dialogs opens — after Advanced Workflow has decided what to propose.

<table id="bkmrk-parametermeaning-dia"><tbody><tr><th>Parameter</th><th>Meaning</th></tr><tr><td><code>Dialog&#58; Enum &#34;DXP AWF Assignee Dialog&#34;</code></td><td>The dialog that opens: <code>Reassignment</code> (Reassign Approval, also when delegating without a substitute), <code>Line Rejection</code> (Reject Related Approval) or <code>Line Send Back</code> (Send Back Line).</td></tr><tr><td><code>ContextRecordID&#58; RecordId</code></td><td>The record the dialog opens for: the document or the line; for a selection of several lines or approvals, the first; for **Reject All**, the workflow's document. Empty where the caller does not know it (see below).</td></tr><tr><td><code>var AssigneeType&#58; Enum &#34;Workflow Approver Type&#34;</code></td><td>The assignee type the dialog shows. Set it to propose another one.</td></tr><tr><td><code>var AssigneeCode&#58; Code&#91;50&#93;</code></td><td>Who is proposed: the user ID for <code>Approver</code>, the code of the workflow user group, the external approver or the external approver group. Leave it empty to propose only the type. It is ignored for <code>Salesperson&#47;Purchaser</code> — the salesperson/purchaser comes from the document.</td></tr></tbody></table>

## How the proposal comes about

1. What the workflow proposes: only when a line is rejected — the stage's rejection group, if one is set up.
2. Otherwise **Default Assignee Type** from the **AWF Setup**, if it is set.
3. Otherwise the type the open approval of `ContextRecordID` is assigned to – the type only, `AssigneeCode` stays empty. Not for `Line Send Back`; approvals from before version 1.16 do not know their type.
4. Otherwise **Approver**.
5. Then the event. The subscriber sees the result of 1–4 in `AssigneeType` and `AssigneeCode` and has the last word.
6. Last: if the dialog does not offer the type, it becomes **Approver** with no code. The two line dialogs offer no external types.

## Example: purchase documents to the purchasing group

```
codeunit 50111 "MY AWF Assignee Proposal"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP AWF Assignee Defaults", 'OnAfterGetDefaultAssignee', '', false, false)]
    local procedure ProposePurchasingGroup(Dialog: Enum "DXP AWF Assignee Dialog"; ContextRecordID: RecordId; var AssigneeType: Enum "Workflow Approver Type"; var AssigneeCode: Code[50])
    begin
        if Dialog <> Dialog::Reassignment then
            exit;
        // Purchase documents and their lines go to the purchasing group.
        if not (ContextRecordID.TableNo() in [Database::"Purchase Header", Database::"Purchase Line"]) then
            exit;

        AssigneeType := AssigneeType::"Workflow User Group";
        AssigneeCode := 'PURCHASING';
    end;
}
```

## Opening the dialogs from your own code

If your code opens one of the dialogs, pass the record along so subscribers see it:

- Codeunit `DXP AWF Page Extension Helper`: `GetReassignmentInput(ContextRecordID, OffersRejectionReview, …)`; for a selection, `GetContextRecordID(…)` (sales lines, purchase lines, approval entries) returns the first record.
- Codeunit `DXP AWF Approval Integration`: `PrepareDelegateBatch(ContextRecordID, …)` and `GetLineRejectionInput(LineReference, ContextRecordID, TemplateCode, StageCode, …)`.
- If you open one of the pages `DXP AWF Workflow Reassignment`, `DXP AWF Line Rejection` or `DXP AWF Line Send Back` yourself, call `SetContextRecordID` before `RunModal`.

The older overloads without `ContextRecordID` remain; they pass an empty record.

## What the event does not change

- It is only a **proposal**. The user can change the type and the assignee in the dialog.
- **Send Back Line** still opens on **Approver of the Stage**; the proposal applies once the reviewer turns that off.
- The checks on confirming stay: an assignee the four-eyes principle excludes is still refused — even if a subscriber proposed them.
- Without a subscriber, nothing changes.

## Related pages

- **Module: Approval Reassignment**
- **Module: Rejection Handling** — rejection group and Send Back Line
- **AWF Setup** — **Default Assignee Type**