Skip to main content

Sales governance policy sweep

Re-evaluates open sales orders and quotations whose governance verdict was reached under a sales governance policy set that is no longer in force, and holds and routes the ones that now breach.

At a glance​

Batch classMGCWardenSalesGovSweep (RunBaseBatch; caption Warden sales governance policy sweep)
Menu itemMGCWardenSalesGovSweepMenuItem, label Sales governance policy sweep
Menu pathSystem administration → Setup → Sales governance policy sweep
Run historySystem administration → Setup → Sales governance sweep runs (MGCWardenSalesGovSweepRuns), which also has a button for the menu item
Who may run itPrivilege MGCWardenSalesGovSweepPriv (Run the Warden sales governance policy sweep), in duty MGCWardenPolicyActivationDuty, in role Warden controls owner (MGCWardenControlsOwner). The run history page is also granted read through MGCWardenGuardInquiryPriv (Warden controls owner, Warden count supervisor, Warden guard administrator). The API operation MGCWardenBatchService.runSalesGovSweep sits on the same privilege
Feature toggleWarden Sales Governance (MGCWardenSalesGovFeature). With it off the run stands down: it writes a Skipped run record and examines nothing
Company scopePer legal entity. It reads and writes the company it runs in only
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
Setup-gap rulesNone watch this sweep or its schedule

Purpose and business justification​

When a user saves or confirms a governed sales document, Warden evaluates it and stores the verdict on the document's side-record, MGCWardenSalesGovState. To avoid re-blocking orders in the middle of a transaction, MGCWardenSalesGovTrigger only re-evaluates a document when its content changes. Policy rows are deliberately left out of that content digest.

The consequence is a gap. After a threshold is tightened, an open document keeps the verdict it was given under the old policy until its content happens to change. An order judged under a loose policy could be confirmed under a tight one. This sweep closes that gap. It does not change the trigger.

How and when it is triggered​

  • Manually, from the menu item or from the button on Sales governance sweep runs. The standard RunBaseBatch dialog opens with the three fields below.
  • As a batch job, if you submit it to the batch framework with a recurrence from the same dialog. Nothing in Warden does this for you.
  • Through the API, MGCWardenBatchService.runSalesGovSweep(customerAccount, maxDocuments, includeUnstamped). It runs synchronously in the caller's session, behind the same menu-item check. See Warden batch framework.

Nothing calls the sweep when a policy is activated. Activating a new policy version moves the policy fingerprint, but the open estate is only re-evaluated when somebody runs the sweep.

Configuration and scheduling options​

Dialog fields​

FieldDefaultMeaning
Customer accountBlankBlank sweeps every customer and every prospect. A value restricts the run to that customer's orders and quotations. A quotation raised against a prospect has no customer account, so a filtered run does not reach it
Maximum documents500 (#DefaultMaxDocuments)Ceiling on documents examined. Must be 1 to 20,000 (#AbsoluteMaxDocuments); validate() refuses anything else rather than correcting it
Include verdicts with no policy stampYesYes treats a verdict with a blank EvaluatedPolicySignature (reached before policy stamping existed) as stale. The dialog help says to leave it Yes until the estate has been swept once

All three values are packed (pack() / unpack(), version 1), so a scheduled task runs with the scope it was given. If the stored parameters cannot be restored, unpack() returns false and RunBase falls back to initParmDefault(). A cap of zero or out of range at run time falls back to 500 (effectiveCap()), and the run record states the cap actually used.

Scheduling​

There is no parameter on MGCWardenParameters for this sweep, and no batch group is set in code. The interval is your decision. The trade-offs:

  • The interval is the window after a policy change in which an open document can still proceed on a verdict reached under the superseded policy set.
  • A run when no policy has changed is cheap. Documents already stamped with the current fingerprint are not candidates, so a steady-state run examines only documents that failed last time, were held, or carry no stamp.
  • A run after a policy activation can be expensive. Every open governed document becomes a candidate, and each evaluation walks the document's lines and, where a margin threshold applies, the cost-basis ladder per line. The cap keeps one run bounded; repeated runs continue where the last stopped.

Because nothing runs the sweep on activation, the window after a policy change lasts until the next run, whether that run is scheduled or started by hand.

What it does​

run()
|-- Sales Governance off? --> write Skipped run, event row, info line; stop
|-- fingerprint = MGCWardenSalesGovPolicySignature::current()
|-- createRun() own transaction; run row in Running
|-- selectCandidates() orders first, then quotations, one shared cap
|-- for each candidate:
| sweepOrder() or sweepQuotation()
| re-check open / held
| MGCWardenSalesEvaluationEngine::evaluate / evaluateQuotation
| classify: Routed / Warned / NoBreach / Failed
| quotation now breaching with a standing approval -> revoke it
| stamp the side-record with the fingerprint (own try)
| sweep line + PolicySweep event row
|-- closeRun() Completed or Partial; event row; evidence store
'-- anything escapes --> failRun(): run Failed + Error exception
  1. Feature check. If MGCWardenSalesGovFeature::isOn() is false, recordFeatureOff() writes a Skipped run whose summary says the run makes no statement about the estate, writes a PolicySweep event row, and returns. Nothing is stamped. This check is load-bearing: the engine returns immediately with the feature off, so a sweep that carried on would stamp documents it never evaluated.
  2. Fingerprint. MGCWardenSalesGovPolicySignature::current() fingerprints the active, effective sales governance policies and their threshold rows. Duplicate settings, price lock and invoice posture are not in it, and nor is item cost.
  3. Run record. createRun() inserts a MGCWardenSalesGovSweepRun row (RunId prefix SW) in status Running, with the fingerprint, filter, cap and a parameter snapshot. The requester is named by subject reference (MGCWardenIdentityVault::refFor), issued before the transaction.
  4. Candidate selection reads MGCWardenSalesGovState and collects RecIds before touching any document:
    • orders: side-records for SalesTable whose EvaluatedPolicySignature differs from the fingerprint, joined to orders whose SalesStatus is None or Backorder, within the customer filter;
    • quotations, only if the cap is not yet spent: side-records for SalesQuotationTable whose status is anything except Confirmed, Lost or Canceled (isSweepableStatus). An unstamped verdict is skipped when Include verdicts with no policy stamp is No. A document that already carries a Warden hold is skipped before the cap is charged, counted as skipped-held, and left unstamped. When the cap is reached the selection stops and the run is marked capped. Only documents that already have a MGCWardenSalesGovState row are in scope.
  5. Per document. The order or quotation is re-read. A document that is no longer open records a Skipped: no longer an open document line. A document held since selection records Skipped: already held and stays unstamped. Otherwise the engine evaluates it with the sweep flag set. The outcome is read from the hold state and the engine's two return values (outcomeOf):
    • held after evaluation: Routed. The engine placed the hold and activated the Warden sales governance approval workflow (MGCWardenSalesGovApprovalTemplate) itself;
    • breach of a policy whose enforcement posture is Warn: Warned. The breach is recorded and the document is not held;
    • neither: NoBreach (compliant);
    • the engine's pass failed open: Failed. The document is not stamped.
  6. Quotation approvals. If a quotation now breaches, is held and carries a standing approval (its ApprovalCarryStamp equals its current content signature), revokeQuotationApproval() clears ApprovalCarryStamp under pessimisticlock in its own transaction and writes a PolicySweep event row saying so. The effect is that the sales order later derived from the quotation is evaluated on its own rather than inheriting the superseded approval. A compliant or Warned quotation keeps its approval: a policy change alone does not lapse it.
  7. Stamp. For every outcome except Failed, the side-record is stamped with the content signature and the fingerprint (MGCWardenSalesGovTrigger::stampEvaluated or MGCWardenQuotationGovTrigger::stampEvaluated). The stamp has its own try. If it cannot be saved the outcome still counts, the line says the stamp was lost, a Warning is filed through MGCWardenSalesGovTrigger::noteStampNotSaved, and the document stays stale for the next run .
  8. Close. closeRun() sets Completed (full scope) or Partial (cap reached), writes the counts and an output summary, writes a PolicySweep event row for the run, records a coverage claim in the audit evidence store (MGCWardenAuditSelfAudit, template PolicySweepCompleted), and prints one info line. A Partial run also files a Warning ControlOutage execution exception.

Transactions​

The run holds no transaction of its own. Each write is its own short transaction: the run row, each engine pass (hold placement, then workflow activation under a lock on the side-record), each revocation, each stamp, each sweep line and the run close. The engine's hold placement requires transaction level 0, which the batch provides. Because nothing is nested, the catch blocks in the sweep run when something fails. (Inside a transaction only a catch naming UpdateConflict or DuplicateKeyException runs; every other catch does not. Keeping each write separate is what lets the sweep isolate a failure to one document.)

Concurrency​

The sweep is not in the MGCWardenBatchOverlapGuard population. Two overlapping runs can both examine the same document and each write a line for it. The engine keeps that to one hold and one approval: MGCWardenHoldManager keeps one active hold per document, and the route is raised only after the side-record is re-read under pessimisticlock and the submit lever's own refusal is asked. A user confirming the same order at the same moment goes through the same engine.

Idempotency​

Re-runs are safe. An evaluated document carries the current fingerprint and is not a candidate again until the policy set moves. Running the sweep twice in a row examines nothing the second time, apart from documents that failed or were held.

Dependencies and prerequisites​

  • Warden Sales Governance switched on in Feature management. See Getting started.
  • Active sales governance policies (MGCWardenSalesGovPolicy, activated through the Warden sales governance policy activation workflow). The sweep re-measures documents against whatever is active; it does not create or activate policies.
  • The Warden sales governance approval workflow configured in the company. Without it, a routed document is held and the workflow activation fails (see below). The setup-gap page reports a missing configuration as ApprovalWorkflowMissing when sales governance is in use; that row watches the workflow, not this sweep.
  • Documents already evaluated once. The sweep re-evaluates side-records; it does not discover documents Warden has never evaluated.
  • The account the batch job runs as: it is recorded as the requester and is the account under which the engine raises approvals.

Inputs and outputs​

ReadsWrites
MGCWardenSalesGovState (candidates and stamps)MGCWardenSalesGovSweepRun (one row per run, including Skipped and Failed runs)
SalesTable, SalesQuotationTableMGCWardenSalesGovSweepLine (one row per document reached, with outcome, prior fingerprint and detail)
Active MGCWardenSalesGovPolicy rows and thresholds (fingerprint and evaluation)MGCWardenSalesGovState: EvaluatedPolicySignature and content stamp; ApprovalCarryStamp cleared on revocation
MGCWardenHold (is the document held)Holds and workflow instances, through the engine
MGCWardenEventLog rows of type PolicySweep: one per document reached, one per revocation, one per run
Execution exceptions (see Errors)
An audit evidence store entry per completed run (SalesGovPolicySweep)
One infolog line: examined, routed, skipped as held, approvals revoked, Partial flag

The engine's hold placement also announces HoldPlaced as a business event when business events are switched on in Warden parameters (BusinessEventsEnabled).

Logging and monitoring​

  • Sales governance sweep runs shows each run's scope and outcome, with a Documents tab of lines. The page is read-only. Read Status first: Completed (full scope examined), Partial (document cap reached), Failed, Skipped (feature off or run refused; nothing examined), or Running. The counts are examined, routed, compliant, skipped-held and failed. Warned documents, revoked approvals and lost stamps are reported in words in the output summary, not in columns.
  • Execution exceptions (System administration → Setup → Execution exceptions) carries the Partial warning, a Failed run's error, and per-document errors.
  • Governance event log (System administration → Setup → Governance event log) carries the PolicySweep rows against each document and against the run.
  • Batch job history shows the infolog line for a scheduled run.
  • No setup-gap rule reports that this sweep is unscheduled or stale.

Run records are purged by retention cleanup after OperationalRetentionDays (365 on a new parameters record; zero keeps them). A run still Running, or one whose lines name a document that is still under an active hold, is never purged.

Errors, recovery and troubleshooting​

What happenedWhat you seeWhat to do
Feature offRun Skipped; info line Sales Governance is switched offNothing, or switch the feature on and run again
Cap reachedRun Partial; Warning ControlOutage on the workbenchRun again (it continues from where it stopped) or run in customer slices until a run is Completed
Engine pass failed open for one documentLine Failed; the engine files its own recordFix the cause, often a broken policy row or a cost read failing for one item. The document stays stale and every run tries it again
Failure before the evaluation, or reading its outcomeLine Failed; Error ClassificationFailure naming the documentAs above
Stamp not savedOutcome counted; line and summary say so; Warning on the workbenchNothing; the next run evaluates it again
Workflow activation failedDocument held with no work item; Critical WorkflowActivationFailure exception naming MGCWardenSalesGovRouteRetryConfigure the workflow if missing, then Retry the exception, or press Submit for sales governance approval on the reconfirmation tracking list
Approval could not be revokedError ClassificationFailure naming the quotationThe carry stamp may still be set; investigate before the quotation is converted
Sweep line could not be writtenWarning EventLogFailure; counts and event log still carry the outcomeNothing
Whole run failedRun Failed; Error ControlOutageRead the exception, fix the cause, run again. Documents not reached stay stale

A run that is killed (an AOS restart) leaves its row in Running. Nothing closes it later. It is safe to run again: the documents it stamped are done, the rest are still candidates.

Impact on other functionality​

  • Holds placed by the sweep block the document at the sales fulfillment, send, confirm and emit gates while Sales Governance is on, exactly as a hold placed at confirmation would. Approvers see a normal sales governance approval.
  • Revoked quotation approvals mean the derived sales order is evaluated on its own at conversion instead of inheriting the approval.
  • Locks. Each route and each revocation locks one MGCWardenSalesGovState row for the length of a short transaction. Nothing is locked across the run.
  • Not covered. A change to item cost can change a margin verdict without moving the fingerprint; the sweep will not notice it. To force re-evaluation after a cost change, run filtered slices or activate a new policy version. The sweep never re-baselines MGCWardenFieldBaseline.
  • Stranded sales holds are not recovered. Already-held documents are skipped, so a sales hold whose approval was canceled is not re-routed by this sweep. The setup-gap page reports such holds (StrandedHold); recovery is the Submit for sales governance approval button or the workbench retry.
  • If the sweep never runs, open documents keep verdicts reached under superseded policies until their content changes.