Sla
Sla(config)
Creates an SLA definition (contract_sla): a timer that tracks service commitments
against task records. SLAs measure response time, resolution time, or other
time-based targets by starting, pausing, resuming, and stopping a clock based on
configurable conditions.
Usage
import { Sla } from '@servicenow/sdk/core'
Sla({
$id: Now.ID['p1-incident-response'],
name: 'Priority 1 Incident Response',
table: 'incident',
duration: Duration({ hours: 4 }),
schedule: 'b1992362eb601100fcfb858ad106fe16',
conditions: {
start: 'priority=1',
stop: 'state=6',
},
})
Parameters
config
Sla
The SLA configuration object.
Properties:
-
$id (required):
string | number | ExplicitKey<string> -
name (optional):
stringDisplay name of the SLA definition shown in admin views and reports. -
table (optional, default:
'incident'):keyof TablesThe task table this SLA applies to. The SLA timer attaches to records in this table. -
type (optional, default:
'SLA'):'SLA' | 'OLA' | 'Underpinning contract'The kind of service agreement.- SLA: Service Level Agreement between the IT organization and its customers.
- OLA: Operational Level Agreement between internal IT groups.
- Underpinning contract: Agreement with an external vendor or supplier.
-
active (optional, default:
true):booleanControls whether this SLA definition is evaluated against new task records. Inactive SLAs stop attaching to new records but do not affect already-running timers. -
target (optional):
'response' | 'resolution'Whether this SLA measures response time (first meaningful action) or resolution time (issue fully resolved). Affects reporting and which SLA fields are populated on the task. -
domainPath (optional, default:
'/'):stringDomain path for domain-separated instances. Controls which domain this SLA definition belongs to.
Duration and Schedule
These properties control how the SLA timer calculates elapsed time.
-
duration (optional):
DurationFixed duration for the SLA. Use the globalDuration()helper. Required whendurationTypeis not set (user-specified duration mode).duration: Duration({ hours: 4 })
duration: Duration({ days: 1, hours: 2, minutes: 30 }) -
durationType (optional):
string | Record<'cmn_relative_duration'>Reference to a relative duration record that calculates the deadline dynamically based on field values. When set, the SLA uses relative duration mode anddurationis restricted. Pass a sys_id string or aRecord()reference. -
relativeDurationWorksOn (optional, default:
'Task record'):'Task record' | 'SLA record'Which record the relative duration calculation reads field values from. Only relevant whendurationTypeis set. -
schedule (optional):
string | Record<'cmn_schedule'>Reference to a schedule record that defines business hours. The timer only counts time during scheduled hours. Required whenscheduleSourceis'sla_definition'(the default). Pass a sys_id string or aRecord()reference. -
scheduleSource (optional, default:
'sla_definition'):'sla_definition' | 'task_field' | 'no_schedule'Where the schedule comes from.- sla_definition: Uses the
scheduleproperty on this SLA definition.scheduleis required. - task_field: Reads the schedule from a field on the task record.
scheduleSourceFieldis required. - no_schedule: Timer runs on wall-clock time with no business-hours filtering.
schedule,timezoneSource,timezone, andscheduleSourceFieldare restricted.
- sla_definition: Uses the
-
scheduleSourceField (optional):
stringDot-walked field path on the task record containing a schedule reference (e.g.,'cmdb_ci.schedule'). Required whenscheduleSourceis'task_field'.
Conditions
Conditions control the SLA timer lifecycle. Each condition is an encoded query string that is evaluated against the task record on every update.
-
conditions (optional):
objectGrouped conditions object for the SLA timer lifecycle.Nested properties:
-
start (optional):
stringEncoded query that starts the SLA timer when matched (e.g.,'priority=1'). -
stop (optional):
stringEncoded query that stops the timer and marks the SLA as achieved or breached (e.g.,'state=6'). -
pause (optional):
stringEncoded query that pauses the timer. Restricted whendurationTypeis set (relative duration mode). -
resume (optional):
stringEncoded query that resumes the timer after a pause. Restricted whendurationTypeis set orwhenTo.resumeis'no_match'. -
reset (optional):
stringEncoded query that resets the SLA timer. TheresetActionproperty controls whether the SLA is cancelled or completed on reset. -
cancel (optional):
stringEncoded query that cancels the SLA. Restricted whenwhenTo.cancelis not'on_condition'.
-
-
advancedConditionType (optional, default:
'none'):'none' | 'advanced' | 'advanced_journal' | 'advanced_system' | 'advanced_journal_and_system'Enables advanced scripted condition evaluation instead of simple encoded queries. -
conditionType (optional):
string | Record<'sla_condition_class'>Reference to a task SLA condition class record for custom condition evaluation logic.
Timer Behavior
-
resetAction (optional, default:
'cancel'):'cancel' | 'complete'What happens when the reset condition is met.- cancel: Cancels the current SLA instance and optionally restarts it.
- complete: Marks the SLA as completed.
-
whenTo (optional):
objectControls when resume and cancel actions are evaluated.Nested properties:
-
resume (optional, default:
'on_condition'):'no_match' | 'on_condition'When to resume the SLA after a pause.- on_condition: Resumes when the
conditions.resumequery matches. - no_match: Resumes when the
conditions.pausequery no longer matches. When set to'no_match',conditions.resumeis restricted.
- on_condition: Resumes when the
-
cancel (optional, default:
'on_condition'):'no_match' | 'on_condition' | 'never'When to cancel the SLA.- on_condition: Cancels when
conditions.cancelmatches. - no_match: Cancels when the start condition no longer matches.
- never: The SLA can never be cancelled by conditions.
When not
'on_condition',conditions.cancelis restricted.
- on_condition: Cancels when
-
Retroactive Start
Controls whether an SLA timer can be backdated to an earlier time on the task record, useful for SLAs that should have started counting before the start condition was met.
-
retroactive (optional):
objectRetroactive behavior configuration.Nested properties:
-
start (optional, default:
false):booleanWhether to retroactively set the SLA start time to a past timestamp. Whentrue,setStartTois required. -
setStartTo (optional):
SetStartToThe task field whose value becomes the retroactive start time. Required whenstartistrue. Valid values:'sys_created_on'-- Created date'opened_at'-- Opened date'resolved_at'-- Resolved date'closed_at'-- Closed date'work_start'-- Actual start'work_end'-- Actual end'due_date'-- Due date'expected_start'-- Expected start'follow_up'-- Follow up date'reopened_time'-- Last reopened at'approval_set'-- Approvals set date'sys_updated_on'-- Last updated date
-
pause (optional, default:
true):booleanWhether to retroactively apply pause conditions during the backdated period. Only applicable whenstartistrue. Restricted whendurationTypeis set (relative duration mode).
-
Timezone
-
timezoneSource (optional, default:
'task.caller_id.time_zone'):TimezoneSourceWhere to get the timezone for SLA calculations. Valid values:'task.caller_id.time_zone'-- The caller's timezone'task.caller_id.location.time_zone'-- The caller's location timezone'task.cmdb_ci.location.time_zone'-- The CI's location timezone'task.location.time_zone'-- The task's location timezone'sla.timezone'-- Use thetimezoneproperty on this SLA definition
-
timezone (optional):
TimeZoneExplicit timezone for SLA calculations (e.g.,'US/Pacific','America/New_York'). Only applicable whentimezoneSourceis'sla.timezone'. Restricted otherwise.
References
-
overrides (optional):
string | Record<'contract_sla'>Reference to another SLA definition that this one overrides. Used when a more specific SLA should take precedence over a general one. -
workflow (optional):
string | Record<'wf_workflow'>Reference to a legacy workflow to trigger when the SLA timer reaches milestones (e.g., 50% elapsed, 75% elapsed, breached). Pass a sys_id orRecord()reference. -
flow (optional):
string | Record<'sys_hub_flow'>Reference to a Flow Designer flow to trigger at SLA milestones. Preferred overworkflowfor new implementations. -
vendor (optional):
string | Record<'core_company'>Reference to a vendor or company record. Relevant for underpinning contracts to track which external vendor is responsible.
Logging
- enableLogging (optional, default:
false):booleanEnables detailed debug logging for this SLA definition. Useful for troubleshooting why an SLA timer started, paused, or stopped unexpectedly. Disable in production to avoid log noise.
Validation Rules
The SLA plugin enforces build-time validation where field requirements depend on other field values:
Duration type validations:
- When
durationTypeis empty (user-specified duration):durationis mandatory, andscheduleis mandatory whenscheduleSourceis'sla_definition'. Theconditions.pause,conditions.resume, andwhenTo.resumefields are allowed. - When
durationTypeis a relative duration:duration,conditions.pause,conditions.resume, andwhenTo.resumeare restricted (warning). Existing values are preserved but cannot be modified.
Schedule source validations:
- When
scheduleSourceis'no_schedule':schedule,timezoneSource,timezone, andscheduleSourceFieldare restricted (warning). Theschedulefield is automatically set to a default value. - When
scheduleSourceis'task_field':scheduleanddurationare restricted (warning), andscheduleSourceFieldis mandatory. - When
scheduleSourceis'sla_definition'(default):scheduleis mandatory.
Retroactive start validations:
- When
retroactive.startisfalseor not set:retroactive.setStartToandretroactive.pauseare restricted (warning). - When
retroactive.startistrue:retroactive.setStartTois mandatory, andretroactive.pauseis allowed. - When
retroactive.startistrueANDdurationTypeis a relative duration:retroactive.pauseis restricted (warning).
Condition field validations:
- When
timezoneSourceis'sla.timezone': thetimezonefield is allowed. Otherwise, it is restricted (warning). - When
whenTo.resumeis'no_match':conditions.resumeis restricted (warning). - When
whenTo.cancelis not'on_condition':conditions.cancelis restricted (warning).
Duration format validation:
- The
durationproperty must use theDuration()helper function. Plain objects (e.g.,{ hours: 4 }) produce a diagnostic error.
Examples
Basic SLA with Duration
Track resolution time for priority 1 incidents with a 4-hour deadline during business hours.
import { Sla } from '@servicenow/sdk/core'
export const P1IncidentResolution = Sla({
$id: Now.ID['p1-incident-resolution'],
name: 'Priority 1 Incident Resolution',
table: 'incident',
active: true,
target: 'resolution',
duration: Duration({ hours: 4 }),
schedule: 'b1992362eb601100fcfb858ad106fe16',
conditions: {
start: 'priority=1',
stop: 'state=6',
},
resetAction: 'cancel',
whenTo: {
resume: 'on_condition',
cancel: 'on_condition',
},
})
SLA with Relative Duration and Schedule from Task
Use a relative duration record to compute the deadline dynamically, and read the schedule from the task's CI.
import { Sla } from '@servicenow/sdk/core'
export const DynamicDeadlineSla = Sla({
$id: Now.ID['dynamic-deadline-sla'],
name: 'Dynamic Deadline from CI Schedule',
table: 'incident',
active: true,
type: 'OLA',
durationType: 'a9e0c28d97710200e40ce648f053af56',
relativeDurationWorksOn: 'Task record',
scheduleSource: 'task_field',
scheduleSourceField: 'cmdb_ci.schedule',
timezoneSource: 'task.cmdb_ci.location.time_zone',
conditions: {
start: 'priority=2',
stop: 'state=6',
},
})
SLA with Conditions and Retroactive Start
Create an SLA that retroactively starts from the record creation time, with pause/resume conditions and a flow trigger.
import { Sla } from '@servicenow/sdk/core'
export const RetroactiveSla = Sla({
$id: Now.ID['retroactive-response-sla'],
name: 'Retroactive Response SLA',
table: 'incident',
active: true,
target: 'response',
duration: Duration({ days: 1, hours: 8 }),
schedule: 'b1992362eb601100fcfb858ad106fe16',
timezoneSource: 'sla.timezone',
timezone: 'US/Pacific',
flow: '828f267973333300e289235f04f6a7a3',
conditions: {
start: 'priority=1^state=1',
stop: 'comments!=NULL',
pause: 'state=3',
resume: 'state=2',
cancel: 'state=7',
},
whenTo: {
resume: 'on_condition',
cancel: 'on_condition',
},
retroactive: {
start: true,
setStartTo: 'sys_created_on',
pause: true,
},
enableLogging: true,
})