Preventive maintenance (PM)

Manage PM templates and schedules for assets; generate work orders when PMs are due. Set tenant context before calling these methods.

List templates and schedules

List PM templates and schedules

await client.setTenant(tenantId)

const templates = await client.pm.listTemplates()
// PmTemplateRow[]

const checklistItems = await client.pm.listTemplateChecklistItems()
// PmTemplateChecklistItemRow[]

const schedules = await client.pm.listSchedules()
// PmScheduleRow[]

Create and update template

Create a PM template that defines trigger configuration and default work order fields. Requires tenant.admin. Returns the template UUID.

client.pm.createTemplate(params)

const templateId = await client.pm.createTemplate({
  tenantId,
  name: 'Quarterly HVAC inspection',
  triggerType: 'calendar',
  triggerConfig: { every: { months: 3 } },
  description: 'Quarterly preventive inspection of HVAC units',
  estimatedHours: 2,
  workOrderTitle: 'Quarterly HVAC PM',
  workOrderDescription: 'Inspect filters, belts, electrical connections',
  workOrderPriority: 'medium',
  checklistItems: [
    { label: 'Inspect filters', required: true },
    { label: 'Check belts', required: true },
  ],
})
// Returns string (template UUID)

Update an existing template:

client.pm.updateTemplate(params)

await client.pm.updateTemplate({
  tenantId,
  templateId,
  name: 'Quarterly HVAC inspection (rooftop)',
  description: 'Quarterly preventive inspection of rooftop HVAC units',
})

Create and update schedule

Create a PM schedule for an asset. Returns the schedule UUID.

client.pm.createSchedule(params)

const pmScheduleId = await client.pm.createSchedule({
  tenantId,
  assetId: 'uuid-of-asset',
  title: 'Quarterly HVAC PM',
  triggerType: 'calendar',
  triggerConfig: { every: { months: 3 } },
  description: 'Recurring quarterly inspection',
  estimatedHours: 2,
  autoGenerate: true,
  workOrderTitle: 'Quarterly HVAC PM',
  workOrderDescription: 'Inspect filters, belts, electrical connections',
  workOrderPriority: 'medium',
  templateId,
})
// Returns string (schedule UUID)

Update an existing schedule:

client.pm.updateSchedule(params)

await client.pm.updateSchedule({
  tenantId,
  pmScheduleId,
  title: 'Quarterly HVAC PM (rooftop)',
  isActive: true,
  autoGenerate: true,
})

Delete schedule

Delete a PM schedule.

client.pm.deleteSchedule(params)

await client.pm.deleteSchedule({
  tenantId,
  pmScheduleId,
})

Dependencies and generation

Create dependencies between PM schedules and generate due PMs.

client.pm.createDependency and client.pm.generateDuePms

// Make schedule depend on another PM
const dependencyId = await client.pm.createDependency({
  tenantId,
  pmScheduleId,
  dependsOnPmId: 'uuid-of-upstream-pm',
  dependencyType: 'finish_to_start',
})

// Generate due PMs (returns number of generated PMs)
const generatedCount = await client.pm.generateDuePms({
  tenantId,
  limit: 50,
})

Trigger a manual PM for a schedule:

client.pm.triggerManualPm(params)

const workOrderId = await client.pm.triggerManualPm({
  tenantId,
  pmScheduleId,
})
// Returns string (work order UUID)

Due, overdue, upcoming, history

List PM instances across different states.

List due, overdue, upcoming PMs, and history

await client.setTenant(tenantId)

const due = await client.pm.listDue()
// DuePmRow[]

const overdue = await client.pm.listOverdue()
// OverduePmRow[]

const upcoming = await client.pm.listUpcoming()
// UpcomingPmRow[]

const history = await client.pm.listHistory()
// PmHistoryRow[]

Was this page helpful?