Skip to main content

Issue Parts from Your Own Screen

On a work order's Parts Used tab, a technician picks a part, a location and a quantity. A custom technician screen or a barcode scanner workflow does the same thing in code, by calling system.kanoa.inventory.issuePartToWorkOrderEvent.

The function deducts the quantity from stock and records it against the work order. It returns the new inventoryTransactionId and a message that is None on success. To read the issues back, call system.kanoa.inventory.getPartsUsedByWorkOrderEvents.

The call needs the database ids of five things. Your screen or scanner usually knows names, so the script looks the ids up first.

Field in issueInfoMeaningHow the script finds it
workOrderEventIdThe work ordersystem.kanoa.cmms.getWorkOrderEvents by workOrderEventName
partIdThe partsystem.kanoa.inventory.getParts by partNumber
inventoryAssetIdWhere the part came fromsystem.kanoa.asset.getAssets by assetPath of the storeroom
assetIdWhere the part was usedsystem.kanoa.asset.getAssets by assetPath of the machine
quantityHow manyPassed in

notes, unitCost and usedBy are optional.

Issue a part script

The script issues 2 of CF-INS-CNMG432 from CoreForge\Philadelphia\Storage\Parts Room to work order MWO00001, used on CoreForge\Philadelphia\Machining\Machine 1. It then prints the ids, the transaction id and message, and every part issued to that work order.

Issue a part from the Script Console
  1. In the Maintenance course you raised the Machine 1 - Coolant leak work order. In Maintenance → Work Orders, note its work order number.
  2. In the Ignition Designer, open the Script Console (Tools → Script Console).
  3. Paste in issuePartToWorkOrder.py.
  4. Change the values at the top of the script. Set workOrderEventName to the number from step 1, and set partNumber to CF-HOSE-075 and quantity to 3.0.
  5. Run the script.
  6. Check the output. The first line lists the five ids. Then you see the new transaction id and None as the message. Each part issued to the work order is listed last.
  7. In Inventory → Parts, expand CF-HOSE-075. The new issue is in the transaction history, linked to the work order.
Reference Materials: issuePartToWorkOrderEvent

Issues (deducts) a quantity of a part from inventory and records the consumption against a CMMS work order event. This is a cross-module operation: workOrderEventId ties the transaction back to a system.kanoa.cmms work order event, inventoryAssetId identifies the bin/location the part is issued from, and assetId identifies the (maintainable) asset the part was used on. Unless otherwise noted, all fields in issueInfo are required. The operation is attributed to the user identified by userId.


Parameters​

issueInfo Dictionary

- assetIdIntegerWhere the part was used
- inventoryAssetIdIntegerWhere the part came from
- notesStringNot required
- partIdInteger
- quantityFloat
- unitCostFloatNot required
- usedByIntegerNot required
- workOrderEventIdInteger

userId Integer:Id of the user executing the function


Returns​

inventoryTransactionId Integer
message String None if success


Example​

issueInfo = {
'assetId': 340,
'inventoryAssetId': 12,
'notes': 'Replaced worn bearing during PM',
'partId': 8891,
'quantity': 2.0,
'unitCost': 14.75,
'usedBy': 205,
'workOrderEventId': 5502,
}
userId = system.kanoa.security.getIDPUserId({'userName': 'SYSTEM'})
inventoryTransactionId, message = system.kanoa.inventory.issuePartToWorkOrderEvent(issueInfo, userId)
print inventoryTransactionId, message

Read back the parts used​

The last lines of the script show the read-back:

data = system.kanoa.utilities.convertDatasetToJSON(
system.kanoa.inventory.getPartsUsedByWorkOrderEvents({'workOrderEventId': workOrderEventId}))
for row in data:
print row.get('partNumber'), row.get('quantity'), row.get('transactionTypeCode')

getPartsUsedByWorkOrderEvents takes optional filters such as workOrderEventId, partId, assetId and partNumber. An empty dictionary returns every row. Each row holds the transaction, part and location details, including quantity, transactionTypeCode and inventoryAssetPath.

Reference Materials: getPartsUsedByWorkOrderEvents

Returns parts-consumption history sourced from the [cms].[vwPartsUsedByWorkOrderEvent] view, reporting which parts were used against which work order events. All parameters are optional filters passed in a single dictionary, allowing lookups by work order event, inventory transaction, asset, part, or location; omitting paramsDict keys, or passing an empty dictionary, returns the full unfiltered result set.


Parameters​

paramsDict Dictionary: Optional filters. Valid keys include workOrderEventId, inventoryTransactionId, assetId, partId, assetPath, assetName, assetTypeName, partNumber, partDescription, locationCode, locationName, binCode, usedBy


Returns​

data pyDataset


Example​

paramsDict = {'workOrderEventId': 62}

data = system.kanoa.inventory.getPartsUsedByWorkOrderEvents(paramsDict)
data = system.kanoa.utilities.convertDatasetToJSON(data)

for i, row in enumerate(data):
print 'Row %i'%i
for k,v in row.items():
print k,v

break #Just limiting to returning the columns from the first record for display purposes
>>>
Row 0
costCenterCode None
supplierId None
notes None
partId 3
createdByUser jason
assetTypeName None
referenceType None
transactionTypeCode ISSUE
quantitySign -1
inventoryAssetPath Kanoa Box Co\Warehouse\Parts Room
changedDate None
lastUpdated Wed Jul 01 19:36:58 UTC 2026
costCenterId None
referenceNumber None
assetId None
assetPath None
changedBy None
changedByUser None
inventoryAssetId 2968
partCategoryPath BBB
inventoryAssetTypeName Storage Location
supplierName None
lastUpdatedBy jason
uomCode FT
defaultUomId 2
quantity 30.0
partPath BBB\A1
inventoryAssetName Parts Room
transactionDate Wed Jul 01 19:36:58 UTC 2026
transactionTypeName Issue from inventory
createdDate Wed Jul 01 19:36:58 UTC 2026
createdBy 5
inventoryTransactionId 26
unitCost None
assetName None
costCenterName None
inventoryTransactionTypeId 2
partNumber A1
>>>

Use it in your own screen​

Move the lookups and the call into a project script library function, such as inventoryTools.issuePart(workOrderEventName, partNumber, quantity, storeroomPath, assetPath). Then a Perspective button or a scanner handler calls one function and shows the returned message.

tip

If message is not None, the issue did not happen. Show it to the user instead of assuming success.

Use the user's id

The script issues parts as SYSTEM. In a technician screen, look up the signed-in person's id and pass it as userId, so the history names the right person. Use usedBy to record who consumed the part.

You built a script that issues a part from the Parts Room to a work order, reads back the parts used, and is ready to become a library function for your own screen.