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 issueInfo | Meaning | How the script finds it |
|---|---|---|
workOrderEventId | The work order | system.kanoa.cmms.getWorkOrderEvents by workOrderEventName |
partId | The part | system.kanoa.inventory.getParts by partNumber |
inventoryAssetId | Where the part came from | system.kanoa.asset.getAssets by assetPath of the storeroom |
assetId | Where the part was used | system.kanoa.asset.getAssets by assetPath of the machine |
quantity | How many | Passed in |
notes, unitCost and usedBy are optional.
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.
- In the Maintenance course you raised the
Machine 1 - Coolant leakwork order. In Maintenance → Work Orders, note its work order number. - In the Ignition Designer, open the Script Console (Tools → Script Console).
- Paste in
issuePartToWorkOrder.py. - Change the values at the top of the script. Set
workOrderEventNameto the number from step 1, and setpartNumbertoCF-HOSE-075andquantityto3.0. - Run the script.
- Check the output. The first line lists the five ids. Then you see the new transaction id and
Noneas the message. Each part issued to the work order is listed last. - In Inventory → Parts, expand
CF-HOSE-075. The new issue is in the transaction history, linked to the work order.
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.
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.
If message is not None, the issue did not happen. Show it to the user instead of assuming success.
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.