Skip to main content

Count consolidation run

Turns accepted count-case adjustments into native counting journals, one journal per warehouse and consolidation window found in the queue. Count Governance (Package C).

At a glance​

Batch classMGCWardenCountConsolidationRun (caption Warden count consolidation)
Menu itemMGCWardenCountConsolidationMenuItem, label Count consolidation run
Menu pathSystem administration → Setup → Count consolidation run
Who may run itMGCWardenPolicyAuthorPriv (Update grant) → MGCWardenPolicyAuthoringDuty → Warden guard administrator (MGCWardenGuardAdministrator), plus the platform's System administrator. The Warden count supervisor role does not get it: that role carries only MGCWardenCountProcessingDuty and MGCWardenGuardInquiryDuty. Also callable over the batch API as MGCWardenBatchService.runCountConsolidation, behind the same menu item
Feature toggleWarden Count Governance (MGCWardenCountGovFeature, default off). Stands down when off: run() logs "Warden Count Governance is off; consolidation skipped." and touches nothing
Company scopePer legal entity. It reads and writes the company the task runs in; every table it uses is per company
Scheduled by defaultNo. Nothing in the product creates a batch job for it
RecurrenceYou choose. No recurrence is stated in code or docs; see Configuration and scheduling options for the trade-off
Setup-gap rules that watch itNone watch the schedule. Two watch its prerequisite on every Active count policy: CountNoConsolidationJournal and CountConsolidationJournalUnusable

Purpose and business justification​

When a count case is accepted, or a write-off is approved on the aged MISSING queue, Warden does not adjust stock itself. It queues the decision-time signed delta for consolidation (MGCWardenCountCaseService::enqueueAccepted, called on Accept, on write-off, and on the case service's auto-accept branch, which queues with reason code AUTO-ACCEPT). This batch turns that queue into ordinary native counting journals. Native posting stays the only posting path: Warden adds no posting layer of its own (class summary).

Which location a row adjusts. Each caller now names the location. Accept and auto-accept queue at the count location, because nothing was moved. A write-off queues where the stock is: at the policy's MISSING location when the quarantine transfer journal was posted, and at the count location when the quarantine moved nothing (no journal, or a journal deleted unposted). While the quarantine journal exists unposted the write-off is refused, so no row is queued.

Two properties matter to an inventory accountant:

  • The quantity that posts is the quantity that was approved. Each line carries the delta the reviewer accepted, however long the row waited and however on-hand moved since.
  • Journals are left for native review by default. Auto-posting happens only where the count policy elects it.

Without this batch, accepted adjustments never reach the inventory: the case is closed, but on-hand stays wrong.

How and when it is triggered​

  • Scheduled batch job, created by an administrator from the menu item's dialog (Run in the background). Nothing schedules it out of the box.
  • Run now from the menu item, interactively. canRunInNewSession() returns true, so an interactive run is marshalled to a second session for the same user and shows a cancellable progress form.
  • Batch API: MGCWardenBatchService.runCountConsolidation, which first checks MGCWardenApiDispatch::canRun on the menu item and refuses to start inside a transaction.

There is no event-driven trigger. Accepting a case only writes a queue row.

Configuration and scheduling options​

Dialog. The class has no dialog fields. pack() returns conNull() and unpack() accepts anything, so the dialog shows only the standard batch tab (batch group, recurrence and so on).

Count policy fields (on System administration → Setup → Count governance policies, versioned, changed on a Draft version and activated through the count policy activation workflow):

FieldLabelEffect on this batch
ConsolidationJournalNameCounting journal nameThe native journal name each journal is created under. It must exist and be of type Counting (InventJournalType::Count), or the whole group fails
ConsolidationAutoPostAuto-post consolidation journalYes posts the journal through the standard pipeline straight after creation. Defaults off (field help: "a deliberate doctrine divergence")
ConsolidationWindowHoursConsolidation window (hours)Decides the queue row's window key when the case is accepted, not when this batch runs. 0, or 24 and above, gives one window per warehouse per calendar day; 1 - 23 splits the day into clock-aligned buckets of that many hours

The window key is built by MGCWardenCountCaseService::windowKey as <warehouse>-<date> or <warehouse>-<date>-H<bucket>. The date is the session date; the hour bucket is the UTC hour divided by the window length.

Count parameters (System administration → Setup → Count governance parameters, MGCWardenCountParameters): BusinessEventsEnabled (Publish business events) gates the two business events this batch sends.

Choosing a recurrence. The batch does not wait for a window to close. Every run journalises every row that is Queued at that moment, whatever its window. So:

  • run it once per window, after the window ends, and each warehouse and window gets one journal;
  • run it more often than the window, and a window that is still filling is split across several journals, one per run that found rows in it;
  • run it less often, and accepted adjustments wait longer before they reach a journal, so on-hand stays wrong for longer.

The policy default is "daily per warehouse" (field help on ConsolidationWindowHours). No recurrence for the batch itself is stated anywhere.

Batch group. No guidance in code. Where auto-post is on, the run performs native inventory posting, so put it in a group whose servers are sized for posting.

One job per company. The run sees only its own company's queue. Schedule one job in each legal entity that uses count governance, and do not schedule two in the same company (see concurrency).

What it does​

run()
|- Count Governance off? -> info line, return (nothing touched)
|- for each (WarehouseId, WindowKey) with Queued rows [MGCWardenCountJournalQueue]
| consolidateGroup()
| try
| ttsbegin
| read first Queued row -> its count case -> that case's count policy
| journal name missing / not Counting? -> throw
| insert InventJournalTable (type Count, from the journal name)
| for each Queued row in the group:
| insert InventJournalTrans (decision-time triple)
| row: Queued -> Journalized, JournalId set
| lineage row (CountingJournalLine) + event-log row on the case
| event-log row on the journal
| ttscommit
| business event "Warden count journal created" (outside the transaction)
| policy auto-post? -> autoPost()
| catch -> markGroupFailed()
|- info "N window group(s) processed"

Step by step:

  1. Toggle check. MGCWardenCountGovFeature::isOn(). Off means return at once.
  2. Group discovery. One while select … group by WarehouseId, WindowKey over MGCWardenCountJournalQueue rows in state Queued.
  3. Per group, one transaction (consolidateGroup):
    • The first queued row's case decides the policy, and that policy's ConsolidationJournalName names the journal. Grouping is by warehouse and window, not by policy; if two policies feed one group, the first case's policy version decides (class summary calls this a documented judgment call).
    • A journal name that does not exist, or is not a counting journal, throws. Nothing of the group survives.
    • The journal header is created through the native pattern (initFromInventJournalName, then insert(), which draws the journal number from the journal name's number sequence). Its description reads Warden count consolidation <warehouse> / <window>.
    • Each queued row becomes one InventJournalTrans line. InventOnHand is the on-hand at the location the line adjusts (lineOnHand): at the case's count location, the case's on-hand snapshot at decision (MGCWardenCountCase.OnHandQty); at any other location (a write-off queued at the MISSING location), the on-hand there on the run date, read as the native counting journal reads it (InventSumDatePhysicalDim::onHandQty for the line's dimensions). Counted is that on-hand plus the signed delta, and Qty is the signed delta. The posting quantity is therefore exactly the decision-time delta. TransDate is the run date (systemDateGet()). Until wave 27 a MISSING line showed the count location's snapshot.
    • The line's inventory dimensions are the warehouse's site, the warehouse, and the location when the queue row has one (InventDim::findOrCreate). No other dimension is set.
    • The queue row moves to Journalized and records the journal number. A MGCWardenCountLineage row of kind CountingJournalLine links the case to the journal line. A CountGovernance event-log row is written on the case and one on the journal.
  4. After commit: the business event Warden count journal created (MGCWardenCountJournalCreated), with posting mode AutoPost or NativeApproval, through MGCWardenGovernanceEventSender::sendCount.
  5. Auto-post (autoPost, only when the policy says so): InventJournalCheckPost::newPostJournal and run() - the standard posting pipeline. On success a second transaction moves the group's rows from Journalized to Posted, an event-log row records the auto-post, and the business event Warden count journal posted (MGCWardenCountJournalPosted) is sent.
  6. Closing line: "Warden count consolidation: N window group(s) processed." The count includes groups that failed.

Transaction boundaries. Each group's journal, lines, queue updates, lineage and event-log rows commit or roll back together. Groups are independent of each other. Auto-post runs after the group has committed, so a posting failure never removes the journal. The business events are sent at transaction level 0.

Error handling inside the run. The group's catch is outside the group's transaction, so it runs after the rollback. A catch naming UpdateConflict or DuplicateKeyException runs inside a transaction and every other catch does not; none of the catches in this class names either, and none sits inside a transaction. The event-log writes happen inside the group's transaction, so a failed event-log insert there propagates and fails the group (see MGCWardenEventLogWriter::write).

Concurrency. MGCWardenCountConsolidationRun is not in MGCWardenBatchOverlapGuard's population, so two overlapping runs are not refused. The class relies on its writes being inside one transaction per group: a concurrent loser's updates conflict and roll back rather than journalise the same rows twice (MGCWardenBatchService class summary). The losing run's group catch then marks whatever is still Queued in that group as Failed and files an exception, so an overlap shows up as spurious consolidation failures. Keep to one job per company.

Idempotency. Only Queued rows are picked up, and a row leaves Queued in the same transaction that writes its journal line. A re-run after success finds nothing to do for those rows.

Dependencies and prerequisites​

  • Warden Count Governance switched on in Feature management (GETTING_STARTED §4c).
  • An Active count policy with a valid Counting journal name of type Counting. The setup-gap page reports both failure shapes.
  • The journal name's number sequence must be able to issue a journal number.
  • Count cases accepted, or write-offs approved, so that queue rows exist.
  • For auto-post: whatever native counting-journal posting needs (inventory parameters, posting profiles, open periods). Not confirmed: how native posting treats an item whose storage or tracking dimensions need more than site, warehouse and location, since the lines carry only those. A test that consolidates such an item and posts the journal would settle it.

Inputs and outputs​

DirectionTable / objectWhat
ReadsMGCWardenCountJournalQueueRows in Queued
ReadsMGCWardenCountCaseOn-hand snapshot (OnHandQty), policy reference
ReadsMGCWardenCountPolicyConsolidationJournalName, ConsolidationAutoPost
ReadsInventJournalName, InventLocationJournal name check, warehouse site
WritesInventJournalTable, InventJournalTrans, InventDimOne native counting journal per group; dimensions via findOrCreate
WritesMGCWardenCountJournalQueueQueued → Journalized (→ Posted on auto-post), or Queued → Failed
WritesMGCWardenCountLineageCountingJournalLine lineage per line
WritesMGCWardenEventLogCountGovernance rows on each case and on the journal
WritesMGCWardenExecutionExceptionOn group failure or auto-post failure
Posts (optional)Native counting journal postingThrough InventJournalCheckPost
EventsBusiness eventsWarden count journal created, Warden count journal posted (both gated by MGCWardenCountParameters.BusinessEventsEnabled); execution exception created when an exception is filed and MGCWardenParameters.BusinessEventsEnabled is on
InfologToggle-off line, or the group count line

No run record is written.

Logging and monitoring​

  • Count consolidation queue (System administration → Setup → Count consolidation queue, MGCWardenCountJournalQueueInquiry, read-only, on MGCWardenGuardInquiryPriv) shows each row's state, window key and journal number. Rows sitting in Queued across several runs mean the batch is not running or the feature is off. Rows in Failed have an exception waiting. Over OData the entity is WardenCountJournalQueueEntries.
  • Execution exceptions (System administration → Setup → Execution exceptions) show failed groups and failed auto-posts.
  • Governance event log (System administration → Setup → Governance event log) holds the per-case and per-journal rows.
  • Warden setup gaps (System administration → Setup → Warden setup gaps) shows CountNoConsolidationJournal ("Count policy has no consolidation counting journal name; accepted deltas can never be journalized") and CountConsolidationJournalUnusable ("Consolidation journal name '…' is missing or is not a counting journal, so the consolidation run fails the whole window group") per Active count policy. Nothing on the page says the batch is unscheduled.
  • Batch job history for the job: the infolog lines above.
  • The native counting journal list shows the journals, identified by their description.

Errors, recovery and troubleshooting​

What happenedWhat you seeRecovery
Count Governance offInfo line; rows stay QueuedSwitch the feature on; the next run picks them up
Group failed (bad journal name, number sequence, any error while building the journal)Rows in Failed; an Error exception, area Integration, reason Integration failure: "Count consolidation failed for warehouse …, window …; rows marked Failed. Retry re-queues the group for the next run."Fix the cause (usually the policy's journal name), then press Retry on the exception
Auto-post failedJournal exists unposted; rows stay Journalized; an Error exception, area Integration: "Auto-post of counting journal … failed …; the journal stands for native approval/posting."Open the journal, fix what native posting refused, post it natively. The exception carries no retry handler, so Retry only warns "No retry handler recorded"; dismiss it once the journal is posted
Something failed outside a groupThe batch task ends in errorRe-run; only Queued rows are touched, so a re-run is safe

Retry on a failed group runs MGCWardenConsolidationRetry with the payload [warehouseId, windowKey]. In one transaction it moves exactly that group's Failed rows back to Queued and clears their journal number. It journalises nothing itself: the next consolidation run rebuilds the journal. A group with no Failed rows left counts as success, so a stale exception resolves cleanly. Re-queuing through the exception is the only re-queue path; a blunter "re-queue everything" lever was removed because it would leave exceptions open for groups that were no longer failed.

A failed group's exception names a journal number that does not exist. The document key carries the journal number drawn before the failure, if one was drawn. That journal was rolled back with the rest of the group.

Rows marked Posted only by auto-post. A journal posted natively by a person leaves its queue rows at Journalized; this batch does not revisit them.

What to look at first: the Execution exceptions workbench, then the setup-gap page for the two journal-name rules, then the queue inquiry.

Impact on other functionality​

  • Inventory accuracy. Until this batch runs, accepted count adjustments and approved write-offs are not in on-hand. The count case is already closed, so nothing on the workbench says the stock is still unadjusted; the queue inquiry does.
  • Native journal workflow. The journals are plain native counting journals. Native counting journal approval and posting apply to them unchanged. Not confirmed: whether Warden journal governance (its review bands, which act on inventory journal posting) also evaluates these journals when a journal policy covers their journal name; tracing MGCWardenInventJournalBand_Extension against counting-journal posting would settle it.
  • Locks. Each group holds its transaction while it writes the journal and updates its queue rows. Auto-post takes whatever locks native counting posting takes.
  • Retention. MGCWardenRetentionCleanup removes queue rows only once they are Posted and their case has been purged; a row that never reaches Posted is kept indefinitely so that a stuck adjustment stays visible (Warden retention cleanup).
  • Business-event consumers see one journal created event per group, and a journal posted event only for auto-posted journals.