Skip to main content
Version: 4.5.0

Function: Sla(config)

Creates an SLA definition with conditional field requirements.

The SLA plugin enforces build-time validation rules where field requirements depend on other field values:

Duration Type Validations:

  • When durationType is empty (user specified duration): duration is mandatory, and schedule is mandatory when scheduleSource is "sla_definition". The conditions.pause, conditions.resume, and whenTo.resume fields are allowed.
  • When durationType is a relative duration: duration, conditions.pause, conditions.resume, and whenTo.resume are restricted (warning). Values from existing SLA definitions will be preserved but cannot be modified.

Schedule Source Validations:

  • When scheduleSource is "no_schedule": schedule, timezoneSource, timezone, and scheduleSourceField are restricted (warning). The schedule field is automatically set to a default value.
  • When scheduleSource is "task_field": schedule and duration are restricted (warning), and scheduleSourceField is mandatory.
  • When scheduleSource is "sla_definition" (default): schedule is mandatory.

Retroactive Start Validations:

  • When retroactive.start is false or not set: retroactive.setStartTo and retroactive.pause are restricted (warning).
  • When retroactive.start is true: retroactive.setStartTo is mandatory, and retroactive.pause is allowed.
  • When retroactive.start is true AND durationType is a relative duration: retroactive.pause is restricted (warning).

Condition Field Validations:

  • When timezoneSource is "sla.timezone": the timezone field is allowed. Otherwise, it is restricted (warning).
  • When whenTo.resume is "no_match": conditions.resume is restricted (warning).
  • When whenTo.cancel is not "on_condition": conditions.cancel is restricted (warning).

Usage

// Basic SLA with user specified duration
Sla({
$id: Now.ID['incident-priority-1-sla'],
name: 'Priority 1 Incident Response',
table: 'incident',
duration: Duration({ hours: 4 }),
schedule: 'schedule-sys-id',
conditions: {
start: 'priority=1',
stop: 'state=6',
},
})

// SLA with relative duration
Sla({
$id: Now.ID['incident-relative-sla'],
name: 'Relative Duration SLA',
table: 'incident',
durationType: 'relative-duration-sys-id',
schedule: 'schedule-sys-id',
// Note: duration, conditions.pause, conditions.resume, whenTo.resume are restricted
})

Parameters

config

Sla

The SLA configuration object

Examples

Basic SLA Example

Create an SLA that tracks resolution time for priority 1 incidents

/**
* @title Basic SLA Example
* @description Create an SLA that tracks resolution time for priority 1 incidents
*/

import { Sla } from '@servicenow/sdk/core'

export const Priority1ResolutionSla = Sla({
$id: Now.ID['priority-1-resolution-sla'],
name: 'Priority 1 Resolution',
table: 'incident',
active: true,
duration: Duration({ hours: 4 }),
schedule: '-replace-with-schedule-id-', // sys_id of a schedule record
conditions: {
start: 'priority=1',
stop: 'state=6',
},
})