| name | maintainx-core-workflow-a |
| description | Execute MaintainX primary workflow: Work Order lifecycle management.
Use when creating, updating, and managing work orders through their full lifecycle,
from creation to completion with all status transitions.
Trigger with phrases like "maintainx work order", "create work order",
"work order lifecycle", "maintenance task", "manage work orders".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*), Bash(curl:*), Grep |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
MaintainX Core Workflow A: Work Order Lifecycle
Overview
Master the complete work order lifecycle in MaintainX - from creation through completion. Work orders are the core unit of maintenance operations.
Prerequisites
- Completed
maintainx-install-auth setup
- Understanding of maintenance operations
- MaintainX account with work order permissions
Work Order Lifecycle
┌─────────────┐
│ OPEN │
│ (Created) │
└──────┬──────┘
│
▼
┌─────────────┐
│ IN_PROGRESS │◄────┐
│ (Started) │ │
└──────┬──────┘ │
│ │
┌────────────┴────────────┤
│ │
▼ │
┌─────────────┐ │
│ ON_HOLD │──────────────────┘
│ (Waiting) │
└─────────────┘
│
│ (Resume or Close)
▼
┌─────────────┐
│ DONE │
│ (Completed) │
└─────────────┘
Instructions
Step 1: Create Work Order
import { MaintainXClient } from '../api/maintainx-client';
interface CreateWorkOrderInput {
title: string;
description?: string;
priority: 'NONE' | 'LOW' | 'MEDIUM' | 'HIGH';
assigneeIds?: string[];
assetId?: string;
locationId?: string;
dueDate?: Date;
categories?: string[];
customFields?: Record<string, any>;
}
export async function createWorkOrder(
client: MaintainXClient,
input: CreateWorkOrderInput
) {
const workOrder = await client.createWorkOrder({
title: input.title,
description: input.description,
priority: input.priority,
assignees: input.assigneeIds,
assetId: input.assetId,
: input.,
: input.?.(),
});
.();
.();
.();
workOrder;
}
() {
(client, {
: ,
: ,
: ,
: ,
: ,
});
}
Step 2: Assign Work Order
async function assignWorkOrder(
client: MaintainXClient,
workOrderId: string,
assigneeIds: string[]
) {
console.log(`Assigning work order ${workOrderId} to:`, assigneeIds);
}
async function findAvailableTechnicians(client: MaintainXClient) {
const users = await client.getUsers({ limit: 100 });
const technicians = users.users.filter(
user => user.role === 'TECHNICIAN' || user.role === 'MAINTENANCE'
);
return technicians;
}
Step 3: Work Order Status Transitions
type WorkOrderStatus = 'OPEN' | 'IN_PROGRESS' | 'ON_HOLD' | 'DONE';
interface StatusTransition {
from: WorkOrderStatus;
to: WorkOrderStatus;
reason?: string;
}
const validTransitions: StatusTransition[] = [
{ from: 'OPEN', to: 'IN_PROGRESS' },
{ from: 'IN_PROGRESS', to: 'ON_HOLD', reason: 'Waiting for parts' },
{ from: 'IN_PROGRESS', to: 'DONE' },
{ from: 'ON_HOLD', to: 'IN_PROGRESS' },
{ from: 'ON_HOLD', to: 'DONE' },
];
function isValidTransition(from: WorkOrderStatus, to: WorkOrderStatus): boolean {
return validTransitions.some(t => t.from === from && t. === to);
}
() {
workOrder = client.(workOrderId);
currentStatus = workOrder. ;
(!(currentStatus, newStatus)) {
(
);
}
.();
(notes) {
.();
}
}
Step 4: Complete Work Order with Documentation
interface CompletionReport {
workOrderId: string;
completedBy: string;
completedAt: Date;
timeSpent: number;
partsUsed: { partId: string; quantity: number }[];
notes: string;
attachments?: string[];
}
async function completeWorkOrder(
client: MaintainXClient,
report: CompletionReport
) {
console.log('=== Work Order Completion Report ===');
console.log(`Work Order: ${report.workOrderId}`);
console.log(`Completed By: ${report.completedBy}`);
console.log(`Completed At: ${report.completedAt.toISOString()}`);
console.log(`Time Spent: ${report.timeSpent} minutes`);
if (report.partsUsed.length > 0) {
.();
report..(
.()
);
}
.();
report;
}
Step 5: Full Workflow Example
async function executeMaintenanceWorkflow(client: MaintainXClient) {
const workOrder = await createWorkOrder(client, {
title: 'Scheduled PM - HVAC Unit Inspection',
description: `
Monthly preventive maintenance inspection for HVAC unit.
## Checklist
- [ ] Check filters
- [ ] Inspect belts
- [ ] Verify refrigerant levels
- [ ] Clean coils
- [ ] Test thermostat
- [ ] Document readings
`,
priority: 'MEDIUM',
assetId: 'asset_hvac_001',
locationId: 'loc_building_a',
});
console.log(`\n1. Work order created: ${workOrder.id}`);
const technicians = await findAvailableTechnicians(client);
if (technicians.length > 0) {
console.log(`\n2. Would assign to: ${technicians[0].firstName} ${technicians[0].lastName}`);
}
console.log('\n3. Transitioning to IN_PROGRESS');
.();
(client, {
: workOrder.,
: ,
: (),
: ,
: [
{ : , : },
],
: ,
});
workOrder;
}
Step 6: Query Work Orders
async function queryWorkOrders(client: MaintainXClient) {
const urgent = await client.getWorkOrders({
status: 'OPEN',
priority: 'HIGH',
limit: 20,
});
console.log(`Urgent open: ${urgent.workOrders.length}`);
const assetWOs = await client.getWorkOrders({
assetId: 'asset_pump_001',
limit: 50,
});
console.log(`Asset work orders: ${assetWOs.workOrders.length}`);
const today = new Date().toISOString();
const overdue = await client.getWorkOrders({
status: 'OPEN',
});
const overdueWOs = overdue.workOrders.filter(
wo => wo. && (wo.) < ()
);
.();
{ urgent, assetWOs, overdueWOs };
}
Output
- Created work orders with full metadata
- Proper status transitions
- Completion documentation
- Query results for work orders
Error Handling
| Error | Cause | Solution |
|---|
| 400 Bad Request | Missing title | Ensure title field is provided |
| 404 Not Found | Invalid asset/location ID | Verify IDs exist in system |
| 403 Forbidden | Insufficient permissions | Check user role and plan tier |
| Invalid transition | Wrong status flow | Follow valid transition paths |
Work Order Fields Reference
| Field | Required | Description |
|---|
| title | Yes | Short description of task |
| description | No | Detailed instructions |
| priority | No | NONE, LOW, MEDIUM, HIGH |
| status | Auto | OPEN, IN_PROGRESS, ON_HOLD, DONE |
| assignees | No | Array of user IDs |
| assetId | No | Associated equipment |
| locationId | No | Facility/area |
| dueDate | No | ISO 8601 timestamp |
Resources
Next Steps
For asset and location management, see maintainx-core-workflow-b.