Skip to main content
Like AOF? Give us a star!
If you find AOF useful, please star us on GitHub. It helps us reach more developers and grow the community.

ServiceNow Tools

AOF provides native ServiceNow integration tools for managing incidents, querying CMDB configuration items, and creating change requests through the ServiceNow Table API.

Feature Flag Required: These tools require the itsm feature flag to be enabled during compilation.

Prerequisites

  • ServiceNow instance (any edition)
  • Valid ServiceNow credentials (Basic Auth or OAuth)
  • API access enabled on your instance

Authentication

ServiceNow supports multiple authentication methods:

Basic Auth (Development)

env:
SERVICENOW_USERNAME: "${SNOW_USER}"
SERVICENOW_PASSWORD: "${SNOW_PASS}"
env:
SERVICENOW_ACCESS_TOKEN: "${SNOW_TOKEN}"

Instance URL Format

ServiceNow instance URLs follow this pattern:

https://{instance}.service-now.com

For example:

  • https://company.service-now.com
  • https://companydev.service-now.com

Available Tools

ToolDescriptionUse Cases
servicenow_incident_createCreate incidentsAutomated incident creation
servicenow_incident_queryQuery incidentsIncident search, reporting
servicenow_incident_updateUpdate incidentsStatus changes, work notes
servicenow_incident_getGet incident detailsIncident lookup
servicenow_cmdb_queryQuery CMDBCI discovery, impact analysis
servicenow_change_createCreate change requestsChange management workflows

servicenow_incident_create

Create a new incident in ServiceNow for tracking and resolution.

Parameters:

ParameterTypeRequiredDescription
instance_urlstringYesServiceNow instance URL
usernamestringYesServiceNow username
passwordstringYesServiceNow password
short_descriptionstringYesBrief summary (max 160 chars)
descriptionstringNoDetailed description
urgencystringNo1 (High), 2 (Medium), 3 (Low)
impactstringNo1 (High), 2 (Medium), 3 (Low)
categorystringNoIncident category
subcategorystringNoIncident subcategory
assignment_groupstringNoAssignment group name or sys_id
assigned_tostringNoAssigned user name or sys_id
cmdb_cistringNoConfiguration Item sys_id
caller_idstringNoUser who reported the incident

Priority Calculation:

Priority is automatically calculated from Urgency × Impact:

Impact 1Impact 2Impact 3
Urgency 1P1 (Critical)P2 (High)P3 (Moderate)
Urgency 2P2 (High)P3 (Moderate)P4 (Low)
Urgency 3P3 (Moderate)P4 (Low)P5 (Planning)

Example Agent Configuration:

apiVersion: aof.dev/v1
kind: Agent
metadata:
name: servicenow-incident-agent
spec:
model: google:gemini-2.5-flash
instructions: |
You are a ServiceNow incident management agent.

When creating incidents:
1. Set appropriate urgency and impact
2. Include detailed description
3. Assign to correct group
4. Link to affected CIs

Incident States:
- 1: New
- 2: In Progress
- 3: On Hold
- 6: Resolved
- 7: Closed

tools:
- servicenow_incident_create
- servicenow_incident_query
- servicenow_incident_update

env:
SERVICENOW_INSTANCE_URL: "${SNOW_URL}"
SERVICENOW_USERNAME: "${SNOW_USER}"
SERVICENOW_PASSWORD: "${SNOW_PASS}"

servicenow_incident_query

Query incidents from ServiceNow with filters and pagination.

Parameters:

ParameterTypeRequiredDescription
instance_urlstringYesServiceNow instance URL
usernamestringYesServiceNow username
passwordstringYesServiceNow password
querystringNoEncoded query string
fieldsstringNoComma-separated fields to return
limitintegerNoMax results (default: 50)
offsetintegerNoPagination offset (default: 0)

Encoded Query Syntax:

ServiceNow uses encoded queries for filtering:

# High priority active incidents
priority=1^state!=6

# Incidents assigned to a group
assignment_group.name=Database Team^state=2

# Created in last 24 hours
sys_created_on>javascript:gs.daysAgo(1)

# Multiple conditions with OR
priority=1^ORpriority=2

# Contains text
short_descriptionLIKEerror

Query Operators:

OperatorDescriptionExample
=Equalspriority=1
!=Not equalsstate!=6
>Greater thansys_created_on>2025-01-01
<Less thanpriority<3
LIKEContainsshort_descriptionLIKEerror
^ANDpriority=1^state=2
^ORORpriority=1^ORpriority=2

servicenow_incident_update

Update an existing incident in ServiceNow.

Parameters:

ParameterTypeRequiredDescription
instance_urlstringYesServiceNow instance URL
usernamestringYesServiceNow username
passwordstringYesServiceNow password
sys_idstringYesIncident sys_id
fieldsobjectYesFields to update

Common Update Fields:

{
"state": "2",
"work_notes": "Investigating the issue",
"assigned_to": "john.doe",
"close_code": "Solved (Permanently)",
"close_notes": "Root cause identified and fixed"
}

servicenow_incident_get

Get detailed information about a specific incident.

Parameters:

ParameterTypeRequiredDescription
instance_urlstringYesServiceNow instance URL
usernamestringYesServiceNow username
passwordstringYesServiceNow password
identifierstringYesIncident sys_id or number (e.g., INC0012345)

servicenow_cmdb_query

Query CMDB Configuration Items for incident context and impact analysis.

Parameters:

ParameterTypeRequiredDescription
instance_urlstringYesServiceNow instance URL
usernamestringYesServiceNow username
passwordstringYesServiceNow password
classstringYesCI class name
querystringNoEncoded query string
fieldsstringNoComma-separated fields
limitintegerNoMax results (default: 50)

Common CI Classes:

ClassDescription
cmdb_ci_serverPhysical and virtual servers
cmdb_ci_databaseDatabase instances
cmdb_ci_app_serverApplication servers
cmdb_ci_kubernetes_clusterKubernetes clusters
cmdb_ci_cloud_service_accountCloud accounts
cmdb_ci_vm_instanceVirtual machine instances

Example Agent Configuration:

apiVersion: aof.dev/v1
kind: Agent
metadata:
name: servicenow-cmdb-agent
spec:
model: google:gemini-2.5-flash
instructions: |
You are a ServiceNow CMDB analysis agent.

Query the CMDB to:
1. Find Configuration Items (CIs)
2. Analyze CI relationships
3. Identify impact of outages
4. Correlate incidents with CIs

tools:
- servicenow_cmdb_query
- servicenow_incident_query

servicenow_change_create

Create a change request in ServiceNow.

Parameters:

ParameterTypeRequiredDescription
instance_urlstringYesServiceNow instance URL
usernamestringYesServiceNow username
passwordstringYesServiceNow password
short_descriptionstringYesBrief change summary
descriptionstringNoDetailed description
typestringNoStandard, Normal, Emergency
riskstringNoHigh, Moderate, Low
impactstringNo1 (High), 2 (Medium), 3 (Low)
start_datestringNoPlanned start (ISO 8601)
end_datestringNoPlanned end (ISO 8601)
cmdb_cistringNoAffected CI sys_id
assignment_groupstringNoAssignment group

Change Types:

TypeDescriptionApproval Required
StandardPre-approved, low riskNo
NormalRegular changesCAB approval
EmergencyUrgent changesExpedited approval

Example Agent Configuration:

apiVersion: aof.dev/v1
kind: Agent
metadata:
name: servicenow-change-agent
spec:
model: google:gemini-2.5-flash
instructions: |
You are a ServiceNow change management agent.

Capabilities:
1. Create change requests for infrastructure changes
2. Query CMDB for affected CIs
3. Assess change risk and impact

Change workflow:
1. Identify affected CIs
2. Assess risk and impact
3. Create change request with details

tools:
- servicenow_change_create
- servicenow_cmdb_query

Pre-built Agents

For production-ready agents using these tools, see the Agent Library:

# Run the pre-built agent
aofctl run agent library://itsm/servicenow-ops \
--prompt "Create P1 incident for database connectivity issue"

Rate Limits

  • Default: ~166 concurrent transactions per semaphore
  • Per-user limits: Configurable per instance
  • HTTP 429: Returned when limits exceeded
  • Headers: X-RateLimit-Remaining, X-RateLimit-Reset

Best Practices

  1. Use encoded queries: More efficient than client-side filtering
  2. Limit fields: Use sysparm_fields to reduce payload size
  3. Paginate results: Use sysparm_limit and sysparm_offset
  4. Use display values: sysparm_display_value=true for readable output
  5. Cache static data: CI data, categories, assignment groups

Security Considerations

  1. Credential Management: Store credentials in environment variables
  2. OAuth 2.0 for Production: Recommended over Basic Auth
  3. API Users: Create dedicated users with minimal permissions
  4. Credential Rotation: Rotate credentials regularly
  5. ACL Review: Ensure API access is properly restricted

See Also