Skip to main content

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​

ClassesMGCWardenJournalReversalRouter (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 itemNone 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 pathLever: System administration → Setup → Journal governance queue (MGCWardenJournalReviewQueue), then Submit for journal reversal approval. Retry: System administration → Setup → Execution exceptions, then Retry
Who may run itAnyone 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 toggleMGCWardenJournalGovFeature (Warden Journal Governance, default off). The copy seam, the posting gate and the retry all stand down when it is off
Company scopePer legal entity. MGCWardenJournalGovState, MGCWardenJournalPolicy and MGCWardenHold are per-company tables
Scheduled by defaultNot applicable: not a batch
RecurrenceNot applicable. Runs once per governed copy
Setup-gap rulesApprovalWorkflowMissing (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::resolvePolicy finds 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​

  1. A user, or a batch task, runs the native Copy on an inventory journal.
  2. MGCWardenInventJournalCopy_Extension.run wraps InventJournalCopy.run. Before next run() it tests the toggle and resolves the policy. After next run() returns, the new journal exists (inventJournalTableTo), and the extension calls MGCWardenJournalReversalRouter::routeReversal.
  3. 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:

SettingWhereEffect
Warden Journal Governance featureFeature managementOff: no copy is classified, no posting is gated, Retry stands down
Journal policy with ReversalWorkflow = Yes, Active and effective, covering the journal nameJournal governance policies (MGCWardenJournalPolicyTable), activated through the Warden journal policy activation workflowThe switch. Without it the router governs nothing
Warden journal reversal approval workflowWorkflow editor; see Getting startedWithout 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:

  1. Opens a transaction. Finds or creates the MGCWardenJournalGovState row for the reversing journal (unique on table and record), then re-reads it with pessimisticlock, so a second caller waits here.
  2. Stamps the row: source journal id and RecId, policy code and version, ReversalState = Pending, LastEvaluated.
  3. Places a hold of type JournalGovernance through MGCWardenHoldManager::placeHold, unless one is already active on that journal (asked by hold type, so a banded-review JournalReview hold on the same journal does not count).
  4. Writes two ReversalRouted event-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.
  5. Commits.
  6. Only if this call placed the hold, calls MGCWardenJournalRevApprovalSubmitManager::raiseUnderLock. That opens its own transaction, re-reads the state row with pessimisticlock, asks the workflow runtime whether a reversal approval already exists, and only if not activates the workflow, stamps the correlation id on the JournalGovernance hold and writes a DeltaRequested row ("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:

StateMessage 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​

DirectionElementDetail
ReadsInventJournalTableSource journal (via parmJournalIdFrom) and the new journal (inventJournalTableTo)
ReadsMGCWardenJournalPolicyThrough MGCWardenJournalGuard::resolvePolicy
WritesMGCWardenJournalGovStateReversal fields; ReversalState = Pending
WritesMGCWardenHoldOne JournalGovernance hold on the reversing journal; correlation id stamped on activation
WritesMGCWardenEventLogTwo ReversalRouted rows; one DeltaRequested row on activation
WorkflowMGCWardenJournalRevApprovalTemplateOne instance per reversal
Writes on failureMGCWardenExecutionExceptionSee below
Business eventHoldPlacedDeferred, 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 the MGCWardenJournalGovState rows, including reversals, and carries the lever and a governance timeline button.
  • Governance holds (MGCWardenHolds) shows the JournalGovernance hold.
  • Governance event log (MGCWardenEventLogInquiry) shows ReversalRouted, DeltaRequested and, on posting, the refusal row written by the attestation writer.
  • Execution exceptions (MGCWardenExceptionWorkbench) shows routing and activation failures.
  • Warden setup gaps (MGCWardenSetupGaps): ApprovalWorkflowMissing (area APPROVALWF, route Journal reversal approval) while MGCWardenSetupGapCheck::journalReversalGovernanceInUse is true and the workflow type is not configured; StrandedHold (area STRANDEDHOLD) 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​

FailureWhat Warden doesWhat you seeRecovery
Policy resolution throws before the copyCopy proceeds ungovernedUngovernedAction 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 holdCritical 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 rowNo 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 unpostableError 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 canceledReversalState = Rejected, journal stays unpostablePosting refused with the cancellation sentence aboveMake 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, JournalGovernance and JournalReview, 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.