system.mes.inventory.operation.executeInventoryOperation
Description
Executes an Inventory Operation and creates a new inventory lot record without having to start and then stop the operation. If the Inventory Operation is already started, this will act as a stopInventoryOperation call.
Permissions
This method requires the INVENTORY_OPERATION.EXECUTE permission.
Syntax
system.mes.inventory.operation.executeInventoryOperation(inventoryOperationId, primaryLotIdOrName, quantity, secondaryLotIdOrName, materialIdOrPath, inventoryName, startDateMillis, endDateMillis)
Parameters
| Parameter | Type | Nullable | Description |
|---|---|---|---|
inventoryOperationId | String (ULID) | False | The ID of the inventory operation to execute. |
primaryLotIdOrName | String | False | The ID or name of the primary lot. |
quantity | Double | False | The quantity the inventory operation will process. |
secondaryLotIdOrName | String | True | The ID or name of the secondary lot, if required. When omitted, the operation's configured Secondary Lot Resolution Strategy is used instead, see the note below. |
materialIdOrPath | String | True | The ID or path of the material associated with the inventory operation. |
inventoryName | String | True | The name of the inventory associated with the inventory operation. |
startDateMillis | Long | True | The start timestamp (ms since epoch) for the lot record. |
endDateMillis | Long | True | The end timestamp (ms since epoch) for the lot record. |
When secondaryLotIdOrName is left out, the inventory operation's configured Secondary Lot Resolution
Strategy decides what is recorded:
- Auto Generate generates a lot code.
- Expression evaluates the operation's secondary lot code expression.
- Manual derives nothing, the caller is the source of the value by definition.
- From Location derives nothing, it is not supported for secondary lots.
Whether the operation's Create Lot If Not Found setting has to be enabled for that derivation depends on the operation type:
| Operation type | Derives a secondary lot |
|---|---|
| Consume, Produce, Receive and Consume | Only when Create Lot If Not Found is enabled. With it disabled nothing is derived and no lot genealogy is recorded, because a derived lot could not be created on these paths |
| Unconsume, Scrap, Scrap All, Return, Receive, Ship | Always, whatever Create Lot If Not Found says, because these paths create the secondary lot unconditionally |
A value passed in secondaryLotIdOrName always wins, and is used regardless of the operation type, the
strategy or that setting.
The strategy is materialised on every call to this method, so Auto Generate yields a fresh lot code each
time. Pass secondaryLotIdOrName explicitly when successive calls have to land on the same secondary lot.
A Receive and Consume operation writes two inventory lot records in one go, a receive and a consume, and both carry the same secondary lot. The two record types face opposite ways in track and trace: a receive reads as material arriving into the primary lot from the secondary lot, a consume as material leaving the primary lot into the secondary lot.
The trace graph therefore shows an edge in each direction between that one pair of lots. The secondary lot is both an ancestor and a descendant of the primary lot, and a trace that runs two levels or more comes back round to the lot it started from. This is expected for this operation type and is not corrupt data. No other operation type writes two records, so no other type does this.
Returns
Returns a JSON object of the inventory lot record for the executed inventory operation.
Example Usage
# Execute a full inventory operation in a single call
executedLotRecord = system.mes.inventory.operation.executeInventoryOperation(
'01JPAND53P-BZ61RZHZ-V7C6EEHG', # inventoryOperationId
'01JPBC4H3V-J4X3FYKS-NRNVEKMM', # primaryLotIdOrName
100.0, # quantity
None, # secondaryLotIdOrName
None, # materialIdOrPath
None, # inventoryName
None, # startDateMillis
None # endDateMillis
)
print(executedLotRecord)