BCQuality rule · scmInventoryofficial - Microsoftderived - from the source, no model text

Derive base quantities through the line's unit of measure

Inventory, item ledger entries, reservations, item tracking, and warehouse quantities are measured in the item's base unit of measure. Document and journal lines hold Quantity in the line's "Unit of Measure Code", together with "Qty.

Rule on GitHub · microsoft layer · scm · BC all · tier official · derived

Description

Inventory, item ledger entries, reservations, item tracking, and warehouse quantities are measured in the item’s base unit of measure. Document and journal lines hold Quantity in the line’s "Unit of Measure Code", together with "Qty. per Unit of Measure" and base-unit fields such as "Quantity (Base)". Ten boxes of twelve pieces are 120 base units, not 10. When a line’s Quantity is validated, the table derives the base quantity through its CalcBaseQty procedure. That procedure calls "Unit of Measure Management".CalcBaseQty with the line’s quantity rounding precision and raises an error when rounding would turn a non-zero quantity into a zero base quantity. Code that bypasses this conversion creates a line whose quantity and base quantity disagree, or makes a stock decision in the wrong unit.

Best Practice

On a document or journal line, validate "Unit of Measure Code" before Quantity, and validate both. Validating the unit of measure sets "Qty. per Unit of Measure" from the item unit of measure; validating the quantity then fills the base fields with the correct rounding. Compare line quantities with inventory or availability in base units, for example "Quantity (Base)" or "Outstanding Qty. (Base)".

Outside a line, get the factor with "Unit of Measure Management".GetQtyPerUnitOfMeasure(Item, UnitOfMeasureCode) and convert with its CalcBaseQty or CalcQtyFromBase procedures instead of multiplying by hand. Pass the item unit’s quantity rounding precision where the available overload accepts it.

Reading these fields for display, reporting, or a temporary buffer that is never posted is not a conversion defect. Code that proves the line uses the base unit of measure ("Qty. per Unit of Measure" equal to 1) is also correct, but don’t assume this from the item alone, because a line can use another unit.

See sample: derive-base-quantities-through-the-line-unit-of-measure.good.al.

Anti Pattern

Assigning Quantity directly on an item journal, sales, purchase, or transfer line and then inserting, modifying, or posting it. Also assigning a base field such as "Quantity (Base)" := Quantity, multiplying by a hard-coded or separately looked-up factor without the line’s rounding, or comparing a line’s Quantity with Item.Inventory or another base-unit value. Detection signal: a direct := to Quantity, "Qty. per Unit of Measure", or a (Base) quantity field on a persisted or posted line, or a comparison between a non-base line quantity and an inventory quantity.

See sample: derive-base-quantities-through-the-line-unit-of-measure.bad.al.

References

Examples

Changed by


From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).