Stock inventory, storage and bundles
Read the tenant's reference seed for client-side batch/serial generation
/a/StockInventory_getReferenceLast
Read the tenant's reference seed for client-side batch/serial generation.
When to use this endpoint
Use before generating a reference in the UI. This returns an existing seed, not a newly reserved or incremented reference; simultaneous clients can generate duplicates.
Authentication and permissions
Authenticate with signed API-key fields or a logged-in CRM session. Core_requireLogin(1) explicitly requires authenticated tenant context before any reference/settings lookup. There is no additional page-role check.
Data is scoped to the authenticated tenant. Session CSRF, signed-request checks and account routing still apply. No stockTracking feature gate is enforced in these handlers.
Requires tenant upgrade 796: stock bundle, storage and inventory tables must have deleted/ddate columns before deploying these handlers.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
referenceMethod | Integer-compatible scalar | No | If omitted reads page_settings page=pageStockInventory, field=referenceMethod; missing/falsey setting becomes 0. 0/default latest-created nonblank reference; 1 longest then lexically greatest; 2 blank. Unknown methods use latest-created lookup but are echoed unchanged in type. |
Example request
$seed = FM_api('StockInventory_getReferenceLast', ['referenceMethod'=>'1']);
Example response
{"reference":"BATCH-009","type":1}
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"not logged in"} | No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Reads tenant-wide nonblank references from active stock_inventories without stock, storage, quantity or catalog archive restriction. Method 1 is LENGTH(reference) DESC then reference DESC, not numeric suffix ordering.
- Default method orders cdate descending with no tie-breaker. Falsey result, including the string 0, normalizes to an empty string.
- No pagination, uniqueness reservation, increment or write is performed. CRM2 does the increment locally.
- No exact caller was found in current app JavaScript or m/www for this office endpoint; app stock quantities use the separate mobile sync/transaction paths.
- Only active inventory rows can seed the next reference; deleted sources are excluded, while active zero-balance rows can still qualify.
Side effects
- Read-only; does not reserve the next reference or edit the referenceMethod setting.
See it in Fieldmotion
CRM1
No direct CRM1 caller was found for this exact endpoint; the legacy Stock page uses its separate catalog/container APIs.
CRM2
Open Stock Inventory → Add Reference Number → Generate, or a goods-received entry. The former sends the page's referenceMethod; widgetGoodReceivedEntry calls without it and uses the saved default. Filter Network for StockInventory_getReferenceLast.
Related endpoints
StockInventory_getRequestedDetailsreads stored mapped values; an omitted ID can retrieve all active tenant rows.StockInventory_createDatacreates a new inventory row rather than changing physical warehouse stock.