Journal reversal router
MGCWardenJournalReversalRouter holds and routes for approval a journal that undoes a posted, governed
inventory journal, and keeps it from posting until the reversal is approved.
This is not a batch. The router is a static class with no menu item, no dialog and no schedule. It
runs inside the standard inventory journal Copy function (InventJournalCopy), which Warden extends,
and its gate runs inside standard journal posting. InventJournalCopy is itself a RunBaseBatch that
does not override canGoBatch(), so a copy can be run in batch, and the router then runs in that batch
task. Nothing re-runs the router on a schedule, and there is deliberately no drain for it (see
Errors, recovery and troubleshooting).
At a glance
| Classes | MGCWardenJournalReversalRouter (static router); request seam MGCWardenInventJournalCopy_Extension (chain of command on InventJournalCopy.run); enforcement seam MGCWardenInventJournalCheckPost_Extension (chain of command on InventJournalCheckPost_Movement.postJournal); retry handler MGCWardenJournalRevRouteRetry; lever MGCWardenJournalRevApprovalSubmitManager |
| Menu item | None of its own. Triggered by the native menu item InventJournalCopy (the Copy function on inventory journal forms). Recovery lever: MGCWardenJournalRevApprovalSubmit, label Submit for journal reversal approval, on Journal governance queue |
| Menu path | Lever: System administration → Setup → Journal governance queue (MGCWardenJournalReviewQueue), then Submit for journal reversal approval. Retry: System administration → Setup → Execution exceptions, then Retry |
| Who may run it | Anyone who can run the native journal copy triggers the router. The lever: MGCWardenJournalRevApprovalPriv → MGCWardenJournalRevApprovalDuty → Warden controls owner. Retry: MGCWardenExceptionProcessPriv → MGCWardenExceptionProcessingDuty → Warden guard administrator and Warden controls owner |
| Feature toggle | MGCWardenJournalGovFeature (Warden Journal Governance, default off). The copy seam, the posting gate and the retry all stand down when it is off |
| Company scope | Per legal entity. MGCWardenJournalGovState, MGCWardenJournalPolicy and MGCWardenHold are per-company tables |
| Scheduled by default | Not applicable: not a batch |
| Recurrence | Not applicable. Runs once per governed copy |
| Setup-gap rules | ApprovalWorkflowMissing (and WorkflowNoDefault / WorkflowNoDefaultNoCondition) for the Journal reversal approval workflow when reversal governance is in use; StrandedHold for a reversal hold with no live route after four hours; WorkflowStoppedWithError for a faulted approval |
Purpose and business justification
A journal policy with Posted immutability stops a posted inventory journal being deleted. Warden also makes sure that it is not silently undone. Dynamics 365 has no reverse action for a posted inventory journal. The native way to undo one is to copy it into a new journal, optionally with the sign reversed, and post that. Warden therefore treats that copy as the reversal request.
When the posted journal's name is covered by an active journal policy with ReversalWorkflow = Yes,
the copy is allowed to complete, the new journal is held, and the Warden journal reversal approval
workflow (MGCWardenJournalRevApprovalTemplate) is raised. The reversing journal can be edited and
reviewed but not posted until the approval completes. Gating the posting rather than the copy means the
approver sees the actual reversing document.
What counts as a reversal (resolveReversalPolicy):
- the source journal is posted (
InventJournalTable.Posted= Yes), and MGCWardenJournalGuard::resolvePolicyfinds an active, effective policy for its journal name, and- that policy has
ReversalWorkflow= Yes.
Copying an unposted journal is ordinary duplication and is never routed. The event log records which
signal classified the copy: explicit reverse-sign or explicit storno (the RU-only flags
parmReverseSign_RU / parmStorno_RU), otherwise copy of posted journal.
How and when it is triggered
- A user, or a batch task, runs the native Copy on an inventory journal.
MGCWardenInventJournalCopy_Extension.runwrapsInventJournalCopy.run. Beforenext run()it tests the toggle and resolves the policy. Afternext run()returns, the new journal exists (inventJournalTableTo), and the extension callsMGCWardenJournalReversalRouter::routeReversal.- Later, any attempt to post the reversing journal meets
MGCWardenInventJournalCheckPost_Extension.
The workflow is originated by the user the copy runs as: the person at the client, or the account a batch task runs as.
Configuration and scheduling options
There is nothing to schedule. Configuration is:
| Setting | Where | Effect |
|---|---|---|
| Warden Journal Governance feature | Feature management | Off: no copy is classified, no posting is gated, Retry stands down |
Journal policy with ReversalWorkflow = Yes, Active and effective, covering the journal name | Journal governance policies (MGCWardenJournalPolicyTable), activated through the Warden journal policy activation workflow | The switch. Without it the router governs nothing |
| Warden journal reversal approval workflow | Workflow editor; see Getting started | Without it the hold is placed and the activation fails, leaving the reversing journal held with an exception to retry |
What it does
routeReversal, called after the copy has committed the new journal:
- Opens a transaction. Finds or creates the
MGCWardenJournalGovStaterow for the reversing journal (unique on table and record), then re-reads it withpessimisticlock, so a second caller waits here. - Stamps the row: source journal id and RecId, policy code and version,
ReversalState=Pending,LastEvaluated. - Places a hold of type
JournalGovernancethroughMGCWardenHoldManager::placeHold, unless one is already active on that journal (asked by hold type, so a banded-reviewJournalReviewhold on the same journal does not count). - Writes two
ReversalRoutedevent-log rows, one on the reversing journal and one on the posted source journal, so the source journal's timeline shows that something tried to undo it. - Commits.
- Only if this call placed the hold, calls
MGCWardenJournalRevApprovalSubmitManager::raiseUnderLock. That opens its own transaction, re-reads the state row withpessimisticlock, asks the workflow runtime whether a reversal approval already exists, and only if not activates the workflow, stamps the correlation id on theJournalGovernancehold and writes aDeltaRequestedrow ("Journal reversal approval requested for ..."). The router, the lever and the retry all serialize on this lock, so one reversal gets one work item.
The enforcement side, MGCWardenInventJournalCheckPost_Extension.postJournal, runs inside native
posting's transaction. With the toggle on it calls isPostingGated: the journal is gated when its state
row is a reversal (SourceJournalRecId set), ReversalState is not Approved, and a JournalGovernance
hold is active. A gated posting is recorded out of band (MGCWardenAttestationWriter::attestReversalRefusal)
and refused with one of three sentences from gateReason:
| State | Message the user sees (abridged) |
|---|---|
Pending | "Journal X reverses posted journal Y and its Warden reversal approval is not complete; posting is gated until the reversal is approved." |
Rejected (written only when the approval workflow is canceled) | "... the approval cycle for that reversal was closed because its approval workflow was canceled. Nothing is outstanding and no approval is coming ... Undoing Y now needs a fresh reversal to be raised and approved." |
| Hold standing, no reversal state | "... is held by Warden, but no reversal approval has been raised for it. It cannot post until one is raised and completed." |
A break-glass release of the JournalGovernance hold lifts this gate, because the gate reads that hold.
Coverage. InventJournalCheckPost_Movement posts movement, loss/profit, transfer, BOM, counting,
project and asset journals, and InventJournalCheckPost_Movement_OwnershipChange derives from it.
Tag-counting journals (InventJournalCheckPost_Tag) are not covered.
Transactions. Both copy-seam regions run at transaction level 0: InventJournalCopy.run opens its own
transaction partway through, so the bare catches there do run. The posting gate runs inside
JournalCheckPost.run's transaction, where only a catch naming UpdateConflict or
DuplicateKeyException runs and every other catch does not; its bare catch therefore never runs on a
posting, and a fault in the lookup refuses the posting with the platform's error and records nothing.
The lookup is keyed reads only, which is what keeps that rare.
Idempotency. A second router call for the same reversing journal finds the hold and does not raise a second approval.
Dependencies and prerequisites
- Warden Journal Governance on, a journal policy with
ReversalWorkflow= Yes active for the journal name, and the Warden journal reversal approval workflow configured and active. - Approvers hold
MGCWardenJournalRevApprovalPriv(on the Warden controls owner role). - Number sequences for holds; see Getting started.
Inputs and outputs
| Direction | Element | Detail |
|---|---|---|
| Reads | InventJournalTable | Source journal (via parmJournalIdFrom) and the new journal (inventJournalTableTo) |
| Reads | MGCWardenJournalPolicy | Through MGCWardenJournalGuard::resolvePolicy |
| Writes | MGCWardenJournalGovState | Reversal fields; ReversalState = Pending |
| Writes | MGCWardenHold | One JournalGovernance hold on the reversing journal; correlation id stamped on activation |
| Writes | MGCWardenEventLog | Two ReversalRouted rows; one DeltaRequested row on activation |
| Workflow | MGCWardenJournalRevApprovalTemplate | One instance per reversal |
| Writes on failure | MGCWardenExecutionException | See below |
| Business event | HoldPlaced | Deferred, because the hold is placed inside a transaction; announced later by the journal route drain (MGCWardenJournalRouteDrainBatch::announceHeldJournal) |
Logging and monitoring
- Journal governance queue (
MGCWardenJournalReviewQueue) lists theMGCWardenJournalGovStaterows, including reversals, and carries the lever and a governance timeline button. - Governance holds (
MGCWardenHolds) shows theJournalGovernancehold. - Governance event log (
MGCWardenEventLogInquiry) showsReversalRouted,DeltaRequestedand, on posting, the refusal row written by the attestation writer. - Execution exceptions (
MGCWardenExceptionWorkbench) shows routing and activation failures. - Warden setup gaps (
MGCWardenSetupGaps):ApprovalWorkflowMissing(areaAPPROVALWF, route Journal reversal approval) whileMGCWardenSetupGapCheck::journalReversalGovernanceInUseis true and the workflow type is not configured;StrandedHold(areaSTRANDEDHOLD) when a reversal hold has had no live route for four hours, with the remedy "Resubmit; if canceled, recopy the posted journal".
Errors, recovery and troubleshooting
| Failure | What Warden does | What you see | Recovery |
|---|---|---|---|
| Policy resolution throws before the copy | Copy proceeds ungoverned | UngovernedAction row "Journal reversal-policy resolution failure: the journal copy proceeded ungoverned." | Fix the cause. The copy is not under governance |
Routing throws after the copy (routeReversal rolls back) | Copy stands without a hold | Critical exception, area HoldManager, reason HoldPlacementFailure: "Reversal routing failed ... the reversing journal was created WITHOUT a governance hold and can be posted ungoverned." Plus an UngovernedAction row | No retry handler is attached. The copy seam is the only non-test caller of routeReversal, so nothing places the hold later. Fix the cause, delete the unheld reversing journal, and copy the posted journal again |
| Workflow activation fails (for example, the workflow is not configured) | Hold stands, ReversalState = Pending, journal unpostable | Error exception, area DeltaOrchestrator, reason WorkflowActivationFailure: "Journal reversal approval could not be activated for X; the reversing journal remains held and unpostable until it is resubmitted." | Configure the workflow, then Retry on the exception (MGCWardenJournalRevRouteRetry) or press Submit for journal reversal approval on Journal governance queue |
| Approval canceled | ReversalState = Rejected, journal stays unpostable | Posting refused with the cancellation sentence above | Make a fresh copy of the posted journal; the closed cycle cannot be resubmitted |
The retry handler (MGCWardenJournalRevRouteRetry) re-finds the journal from its payload and closes
the exception without raising anything when the journal is gone, already posted, or Journal Governance is
off. Otherwise it raises through raiseUnderLock and reports success only if the workflow runtime then
holds a reversal approval.
Why there is no drain. Every other route family has an unattended drain; this one deliberately does
not. A reversal exists only because a person copied a posted journal, and the router holds and routes it
in the same pass, so there is no population that quietly owes an approval. MGCWardenJournalRevRouteRetry's
summary records that adding a drain would require a reversal-scoped route claim with it, to avoid two
approvers deciding one undo. The journal route drain does visit reversing journals, but only to announce
the deferred HoldPlaced event; it never raises a reversal approval. See Route drains.
Impact on other functionality
- The native copy is never blocked or unwound by Warden. Only posting of the reversing journal is refused.
- A reversing journal large enough to cross a cost band carries two holds,
JournalGovernanceandJournalReview, which are kept apart by type. Approving the banded review does not free the reversal, and approving the reversal does not satisfy the review. - Copies made in batch route in that batch task, at the same transaction level as an interactive copy.
- With Journal Governance switched off, a reversing journal already held is no longer refused: the posting gate tests the toggle before it reads the state. See Getting started.
Related documentation
- Sales & journal governance users
- Standard batch and periodic processes with Warden installed for the copy, posting and clean-up seams on standard classes
- Route drains for the journal route drain
- Break-glass grant expiry for the break-glass grant that can lift the hold