servicenow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Jace's ServiceNow CLI

Jace 出品的 ServiceNow CLI

Explore and manage ServiceNow instances. Works standalone or with AI agents.
用于探索和管理 ServiceNow 实例,可独立使用也可配合 AI Agent 使用。

Agent Invariants

Agent 遵循准则

MUST follow these rules:
  1. Choose the right output mode
    --json
    when parsing data;
    --md
    when presenting to humans
  2. Use sys_id for updates — All update/delete operations require sys_id
  3. Check auth first — Run
    jsn auth status
    if commands fail
  4. Profile scope — Use
    --profile <name>
    or switch with
    jsn config switch <name>
必须严格遵守以下规则:
  1. 选择合适的输出模式 — 解析数据时使用
    --json
    ;向用户展示内容时使用
    --md
  2. 更新操作使用 sys_id — 所有更新/删除操作都需要提供 sys_id
  3. 优先检查授权 — 如果命令执行失败,先运行
    jsn auth status
    检查授权状态
  4. 配置文件作用域 — 使用
    --profile <name>
    指定配置,或通过
    jsn config switch <name>
    切换激活配置

Output Modes

输出模式

GoalFlagFormat
Parse data, pipe to jq
--json
JSON envelope:
{ok, data, summary, breadcrumbs}
Show results to user
--md
Markdown tables
Automation/scripting
--agent
JSON + quiet + no interactive prompts
Raw data only
--quiet
JSON data without envelope
目标参数格式
解析数据,管道传输到 jq
--json
JSON 封装结构:
{ok, data, summary, breadcrumbs}
向用户展示结果
--md
Markdown 表格
自动化/脚本调用
--agent
JSON 格式 + 静默输出 + 无交互提示
仅输出原始数据
--quiet
无封装的纯 JSON 数据

JSON Envelope

JSON 封装结构

Every command supports
--json
:
json
{
  "ok": true,
  "data": [...],
  "summary": "5 tables",
  "breadcrumbs": [
    {"action": "show", "cmd": "jsn tables show incident", "description": "View details"}
  ]
}
Breadcrumbs suggest next commands for navigation.
所有命令都支持
--json
参数:
json
{
  "ok": true,
  "data": [...],
  "summary": "5 tables",
  "breadcrumbs": [
    {"action": "show", "cmd": "jsn tables show incident", "description": "View details"}
  ]
}
面包屑字段会推荐下一步可执行的导航命令。

Quick Reference

快速参考

TaskCommand
List tables
jsn tables list --json
Show table schema
jsn tables schema incident --json
List table columns
jsn tables columns incident --json
Create table
jsn tables create u_my_table --label "My Table"
Add column to table
jsn tables add-column u_my_table u_field --type string --label "Field"
Query records
jsn records list incident --query "active=true" --json
Show record
jsn records show incident <sys_id> --json
Count records
jsn records count incident --query "priority=1" --json
Create record
jsn records create incident -f short_description="Test" --json
Create with file
jsn records create sys_script -f script=@/tmp/script.js --json
Update record
jsn records update incident <sys_id> -f state=2 --json
Delete record
jsn records delete incident <sys_id> --force --json
List business rules
jsn rules list --table incident --json
Show rule script
jsn rules script <sys_id>
List flows
jsn flows list --active --json
List script includes
jsn script-includes list --json
Show script code
jsn script-includes code <name>
List ACLs
jsn acls list --table incident --json
List update sets
jsn updateset list --json
Set current update set
jsn updateset use <name>
List choices
jsn choices list <table> <column> --json
List jobs
jsn jobs list --json
Run job
jsn jobs run <sys_id>
List forms
jsn forms list --table incident --json
Show list columns
jsn lists show incident --json
List list views
jsn lists list --table incident --json
List UI policies
jsn ui-policies list --table incident --json
List client scripts
jsn client-scripts list --table incident --json
List catalog items
jsn catalog-item list --json
List item variables
jsn catalog-item variables <sys_id> --json
List variable choices
jsn variable choices <name> --json
Add variable choice
jsn variable add-choice <name> "value"
Variable types
jsn variable-types --json
Search docs
jsn docs search <term>
Compare instances
jsn compare tables --source prod --target dev --json
Generate code
jsn generate gliderecord --table incident
Run background script
jsn eval "gs.print(gs.getProperty('instance_name'))"
Run script from file
jsn eval --file /tmp/my_script.js
任务命令
列出所有表
jsn tables list --json
查看表结构
jsn tables schema incident --json
列出表字段
jsn tables columns incident --json
创建表
jsn tables create u_my_table --label "My Table"
为表新增字段
jsn tables add-column u_my_table u_field --type string --label "Field"
查询记录
jsn records list incident --query "active=true" --json
查看记录详情
jsn records show incident <sys_id> --json
统计记录数量
jsn records count incident --query "priority=1" --json
创建记录
jsn records create incident -f short_description="Test" --json
基于文件创建记录
jsn records create sys_script -f script=@/tmp/script.js --json
更新记录
jsn records update incident <sys_id> -f state=2 --json
删除记录
jsn records delete incident <sys_id> --force --json
列出业务规则
jsn rules list --table incident --json
查看规则脚本
jsn rules script <sys_id>
列出流程
jsn flows list --active --json
列出 script includes
jsn script-includes list --json
查看脚本代码
jsn script-includes code <name>
列出 ACLs
jsn acls list --table incident --json
列出更新集
jsn updateset list --json
设置当前使用的更新集
jsn updateset use <name>
列出选项值
jsn choices list <table> <column> --json
列出作业
jsn jobs list --json
运行作业
jsn jobs run <sys_id>
列出表单
jsn forms list --table incident --json
查看列表字段
jsn lists show incident --json
列出列表视图
jsn lists list --table incident --json
列出 UI 策略
jsn ui-policies list --table incident --json
列出客户端脚本
jsn client-scripts list --table incident --json
列出目录项
jsn catalog-item list --json
列出项变量
jsn catalog-item variables <sys_id> --json
列出变量选项值
jsn variable choices <name> --json
新增变量选项值
jsn variable add-choice <name> "value"
查看变量类型
jsn variable-types --json
搜索文档
jsn docs search <term>
实例对比
jsn compare tables --source prod --target dev --json
生成代码
jsn generate gliderecord --table incident
运行后台脚本
jsn eval "gs.print(gs.getProperty('instance_name'))"
运行文件内的脚本
jsn eval --file /tmp/my_script.js

Command Categories

命令分类

Tables & Schema

表与结构

bash
jsn tables list --json                    # All tables
jsn tables list --search "incident"       # Filter by name
jsn tables list --app "global"            # Filter by scope
jsn tables show incident --json           # Table details (alias: get)
jsn tables schema incident --json         # Inheritance tree
jsn tables columns incident --json        # Column definitions
jsn tables create u_my_table --label "My Table"              # Create table
jsn tables create u_assets --label "Assets" --extends cmdb_ci  # Extend existing
jsn tables add-column u_my_table u_desc --type string --label "Description"
jsn tables add-column u_my_table u_ref --type reference --reference sys_user
bash
jsn tables list --json                    # 所有表
jsn tables list --search "incident"       # 按名称筛选
jsn tables list --app "global"            # 按作用域筛选
jsn tables show incident --json           # 表详情(别名:get)
jsn tables schema incident --json         # 继承树
jsn tables columns incident --json        # 字段定义
jsn tables create u_my_table --label "My Table"              # 创建表
jsn tables create u_assets --label "Assets" --extends cmdb_ci  # 继承现有表创建
jsn tables add-column u_my_table u_desc --type string --label "Description"
jsn tables add-column u_my_table u_ref --type reference --reference sys_user

Records (CRUD operations)

记录(CRUD 操作)

bash
jsn records list <table> --json                              # List records
jsn records list <table> --query "active=true" --limit 10    # With filter
jsn records list <table> --fields "number,short_description" # Specific fields
jsn records show <table> <sys_id> --json                     # Single record (alias: get)
jsn records count <table> --query "priority=1"               # Count
jsn records create <table> -f short_description="Test"       # Create with fields
jsn records create <table> -f script=@/tmp/script.js         # Read value from file
jsn records create <table> --data '{"field":"value"}'        # Create with JSON
jsn records update <table> <sys_id> -f state=2               # Update with fields
jsn records update <table> <sys_id> -f script=@/tmp/fix.js   # Update from file
jsn records delete <table> <sys_id> --force                  # Delete
jsn records variables <ritm_sys_id> --json                   # Catalog variables
bash
jsn records list <table> --json                              # 列出记录
jsn records list <table> --query "active=true" --limit 10    # 带筛选条件
jsn records list <table> --fields "number,short_description" # 指定返回字段
jsn records show <table> <sys_id> --json                     # 单条记录详情(别名:get)
jsn records count <table> --query "priority=1"               # 统计数量
jsn records create <table> -f short_description="Test"       # 带字段创建
jsn records create <table> -f script=@/tmp/script.js         # 从文件读取字段值
jsn records create <table> --data '{"field":"value"}'        # 基于 JSON 创建
jsn records update <table> <sys_id> -f state=2               # 按字段更新
jsn records update <table> <sys_id> -f script=@/tmp/fix.js   # 从文件读取内容更新
jsn records delete <table> <sys_id> --force                  # 删除
jsn records variables <ritm_sys_id> --json                   # 目录变量

Business Rules

业务规则

bash
jsn rules list --table incident --json    # Rules on table
jsn rules show <sys_id> --json            # Rule details
jsn rules script <sys_id>                 # Output just the script
bash
jsn rules list --table incident --json    # 表关联的规则
jsn rules show <sys_id> --json            # 规则详情
jsn rules script <sys_id>                 # 仅输出脚本内容

Flows

流程

bash
jsn flows list --json                     # All flows
jsn flows list --active --json            # Active only
jsn flows show <name> --json              # Flow details
bash
jsn flows list --json                     # 所有流程
jsn flows list --active --json            # 仅展示激活的流程
jsn flows show <name> --json              # 流程详情

Script Includes

Script Includes

bash
jsn script-includes list --json           # All script includes
jsn script-includes list --scope global   # Filter by scope
jsn script-includes show <name> --json    # Details
jsn script-includes code <name>           # Output just the code
bash
jsn script-includes list --json           # 所有 script includes
jsn script-includes list --scope global   # 按作用域筛选
jsn script-includes show <name> --json    # 详情
jsn script-includes code <name>           # 仅输出代码内容

ACLs

ACLs

bash
jsn acls list --table incident --json     # ACLs on table
jsn acls show <sys_id> --json             # ACL details
jsn acls script <sys_id>                  # Output condition script
jsn acls check --table incident --operation read  # Test coverage
bash
jsn acls list --table incident --json     # 表关联的 ACL
jsn acls show <sys_id> --json             # ACL 详情
jsn acls script <sys_id>                  # 输出条件脚本
jsn acls check --table incident --operation read  # 测试权限覆盖

Update Sets

更新集

bash
jsn updateset list --json                 # All update sets
jsn updateset show <name> --json          # Details
jsn updateset use <name>                  # Set as current
jsn updateset create <name>               # Create new
jsn updateset parent <child> <parent>     # Set parent
bash
jsn updateset list --json                 # 所有更新集
jsn updateset show <name> --json          # 详情
jsn updateset use <name>                  # 设置为当前使用的更新集
jsn updateset create <name>               # 创建新更新集
jsn updateset parent <child> <parent>     # 设置父更新集

Choices

选项值

bash
jsn choices list <table> <column> --json  # List choices
jsn choices create <table> <column> --value 5 --label "Critical"
jsn choices update <sys_id> --label "New Label"
jsn choices delete <sys_id> --force
jsn choices reorder <table> <column> --mode hundreds
bash
jsn choices list <table> <column> --json  # 列出选项值
jsn choices create <table> <column> --value 5 --label "Critical"
jsn choices update <sys_id> --label "New Label"
jsn choices delete <sys_id> --force
jsn choices reorder <table> <column> --mode hundreds

Jobs & Scheduling

作业与调度

bash
jsn jobs list --json                      # All jobs
jsn jobs list --type scheduled            # Scheduled only
jsn jobs show <sys_id> --json             # Job details
jsn jobs executions <sys_id> --json       # Execution history
jsn jobs run <sys_id>                     # Execute now
bash
jsn jobs list --json                      # 所有作业
jsn jobs list --type scheduled            # 仅展示调度作业
jsn jobs show <sys_id> --json             # 作业详情
jsn jobs executions <sys_id> --json       # 执行历史
jsn jobs run <sys_id>                     # 立即执行

UI Configuration

UI 配置

bash
jsn forms list --table incident --json           # Form views
jsn forms show incident --view default --json    # Form layout
jsn lists list --table incident --json           # List views
jsn lists show incident --json                   # List columns (Default view)
jsn lists show incident --view "Default view"    # List columns for specific view
jsn ui-policies list --table incident --json     # UI policies
jsn ui-policies script <sys_id>                  # Policy script
jsn client-scripts list --table incident --json  # Client scripts
jsn client-scripts script <sys_id>               # Script code
jsn ui-scripts list --json                       # UI scripts
bash
jsn forms list --table incident --json           # 表单视图
jsn forms show incident --view default --json    # 表单布局
jsn lists list --table incident --json           # 列表视图
jsn lists show incident --json                   # 列表字段(默认视图)
jsn lists show incident --view "Default view"    # 指定视图的列表字段
jsn ui-policies list --table incident --json     # UI 策略
jsn ui-policies script <sys_id>                  # 策略脚本
jsn client-scripts list --table incident --json  # 客户端脚本
jsn client-scripts script <sys_id>               # 脚本代码
jsn ui-scripts list --json                       # UI 脚本

Service Portal

服务门户

bash
jsn sp list --json                        # Portals
jsn sp show <id> --json                   # Portal details
jsn sp-widgets list --json                # Widgets
jsn sp-pages list --json                  # Pages
bash
jsn sp list --json                        # 门户列表
jsn sp show <id> --json                   # 门户详情
jsn sp-widgets list --json                # 组件列表
jsn sp-pages list --json                  # 页面列表

Service Catalog

服务目录

bash
jsn catalog-item list --json              # List catalog items
jsn catalog-item list --active --json     # Active items only
jsn catalog-item show <sys_id> --json     # Item details
jsn catalog-item variables <sys_id> --json  # Variables on item

jsn variable show <name_or_sys_id> --json # Variable details
jsn variable choices <name> --json        # Choices for dropdown variable
jsn variable add-choice <name> "value" "Display Text"  # Add choice
jsn variable remove-choice <name> "value" # Remove choice

jsn variable-types --json                 # Variable type reference
Note:
jsn choices
manages
sys_choice
(field-level choices). Use
jsn variable choices
for catalog variable dropdown choices (
question_choice
table).
bash
jsn catalog-item list --json              # 列出目录项
jsn catalog-item list --active --json     # 仅展示激活的目录项
jsn catalog-item show <sys_id> --json     # 项详情
jsn catalog-item variables <sys_id> --json  # 项关联的变量

jsn variable show <name_or_sys_id> --json # 变量详情
jsn variable choices <name> --json        # 下拉变量的选项值
jsn variable add-choice <name> "value" "Display Text"  # 新增选项值
jsn variable remove-choice <name> "value" # 移除选项值

jsn variable-types --json                 # 变量类型参考
注意:
jsn choices
管理的是
sys_choice
(字段级选项值),目录变量下拉选项值(
question_choice
表)请使用
jsn variable choices
管理。

Logs

日志

bash
jsn logs --json                           # Recent logs
jsn logs --level error --json             # Filter by level
jsn logs --source <name> --json           # Filter by source
bash
jsn logs --json                           # 最近日志
jsn logs --level error --json             # 按级别筛选
jsn logs --source <name> --json           # 按来源筛选

Documentation

文档

bash
jsn docs list                             # Available topics
jsn docs gliderecord                      # Show topic
jsn docs search "encoded query"           # Search docs
jsn docs update                           # Refresh cache
bash
jsn docs list                             # 可用主题
jsn docs gliderecord                      # 查看主题内容
jsn docs search "encoded query"           # 搜索文档
jsn docs update                           # 刷新缓存

Cross-Instance Operations

跨实例操作

bash
jsn compare tables --source prod --target dev --json
jsn compare script-includes --source prod --target dev --name "MyUtil"
jsn compare choices --source prod --target dev --table incident --column priority
jsn export script-includes --name "MyUtil" --output ./scripts
jsn export tables --name incident --output ./schema
bash
jsn compare tables --source prod --target dev --json
jsn compare script-includes --source prod --target dev --name "MyUtil"
jsn compare choices --source prod --target dev --table incident --column priority
jsn export script-includes --name "MyUtil" --output ./scripts
jsn export tables --name incident --output ./schema

Raw REST API

原始 REST API

bash
jsn rest get /api/now/table/incident?sysparm_limit=5      # GET (query params auto-encoded)
jsn rest post /api/now/table/incident --data '{"short_description":"test"}'
jsn rest patch /api/now/table/incident/<sys_id> --data '{"state":"2"}'
jsn rest delete /api/now/table/incident/<sys_id>           # Shows confirmation on success
jsn rest get /api/x_myapp/custom_api/resource              # Custom/scoped APIs
bash
jsn rest get /api/now/table/incident?sysparm_limit=5      # GET 请求(查询参数自动编码)
jsn rest post /api/now/table/incident --data '{"short_description":"test"}'
jsn rest patch /api/now/table/incident/<sys_id> --data '{"state":"2"}'
jsn rest delete /api/now/table/incident/<sys_id>           # 执行成功后展示确认信息
jsn rest get /api/x_myapp/custom_api/resource              # 自定义/作用域 API

Background Scripts (eval)

后台脚本(eval)

bash
jsn eval "gs.print(gs.getProperty('instance_name'))"             # Inline script
jsn eval --file /tmp/check_records.js                             # Script from file
echo "gs.print('hello')" | jsn eval                               # Piped from stdin
jsn eval --scope x_myapp_scope "gs.print(gs.getCurrentScopeName())" # Run in app scope
jsn eval --no-rollback "gs.print('skip rollback')"                # Disable rollback recording
jsn eval --no-quota "gs.print('no timeout')"                      # Disable 4-hour timeout
jsn eval "gs.print(JSON.stringify({user: gs.getUserName()}))" --json  # JSON output
Equivalent to "Scripts - Background" in the ServiceNow UI. Uses
sys.scripts.do
internally. Use
gs.print()
or
gs.info()
to produce output. Full server-side API access (GlideRecord, gs, etc.).
bash
jsn eval "gs.print(gs.getProperty('instance_name'))"             # 行内脚本
jsn eval --file /tmp/check_records.js                             # 运行文件内的脚本
echo "gs.print('hello')" | jsn eval                               # 从标准输入读取脚本运行
jsn eval --scope x_myapp_scope "gs.print(gs.getCurrentScopeName())" # 指定应用作用域运行
jsn eval --no-rollback "gs.print('skip rollback')"                # 禁用回滚记录
jsn eval --no-quota "gs.print('no timeout')"                      # 禁用4小时超时限制
jsn eval "gs.print(JSON.stringify({user: gs.getUserName()}))" --json  # JSON 格式输出
功能等价于 ServiceNow UI 中的「脚本 - 后台」,内部使用
sys.scripts.do
实现。使用
gs.print()
gs.info()
生成输出,支持完整的服务端 API 访问(GlideRecord、gs 等)。

Code Generation

代码生成

bash
jsn generate gliderecord --table incident
jsn generate script-include --name "MyUtil"
jsn generate rest --name "MyAPI"
jsn generate acl --table incident --operation read
jsn generate test --table incident
bash
jsn generate gliderecord --table incident
jsn generate script-include --name "MyUtil"
jsn generate rest --name "MyAPI"
jsn generate acl --table incident --operation read
jsn generate test --table incident

Configuration

配置

~/.config/servicenow/         # Global config
├── config.json               #   Profiles and settings
└── credentials.json          #   Auth tokens (fallback)

.servicenow/                  # Per-repo config (optional)
└── config.json               #   Project-specific settings
~/.config/servicenow/         # 全局配置
├── config.json               #   配置文件与设置
└── credentials.json          #   授权令牌(备用)

.servicenow/                  # 仓库级配置(可选)
└── config.json               #   项目专属设置

Profiles

配置文件

bash
jsn config list                           # List profiles
jsn config add                            # Add new profile
jsn config switch <name>                  # Switch active profile
jsn --profile prod tables list            # Use specific profile
bash
jsn config list                           # 列出所有配置
jsn config add                            # 新增配置
jsn config switch <name>                  # 切换激活配置
jsn --profile prod tables list            # 使用指定配置执行命令

Authentication

鉴权

bash
jsn auth login                            # Interactive login
jsn auth status                           # Check auth
jsn auth logout                           # Clear credentials
Environment variables:
  • SERVICENOW_TOKEN
    — Override stored token
  • SERVICENOW_INSTANCE
    — Override instance URL
bash
jsn auth login                            # 交互式登录
jsn auth status                           # 检查鉴权状态
jsn auth logout                           # 清空凭证
环境变量:
  • SERVICENOW_TOKEN
    — 覆盖本地存储的令牌
  • SERVICENOW_INSTANCE
    — 覆盖实例 URL

Interactive Pickers

交互式选择器

Commands with
[optional]
arguments open pickers when omitted:
bash
jsn tables show [<name>]      # Opens picker if name not provided
jsn rules show [<id>]         # Opens picker if id not provided
jsn updateset use [<name>]    # Opens picker if name not provided
Alias:
get
works as an alias for
show
on all commands (e.g.,
jsn records get
,
jsn tables get
).
带有
[可选]
参数的命令在参数缺失时会自动打开选择器:
bash
jsn tables show [<name>]      # 未提供名称时打开选择器
jsn rules show [<id>]         # 未提供ID时打开选择器
jsn updateset use [<name>]    # 未提供名称时打开选择器
别名: 所有命令的
show
都可以用
get
作为别名(例如
jsn records get
jsn tables get
)。

Global Flags

全局参数

--config <path>       # Use specific config file
--profile <name>      # Use specific profile
--json                # Output as JSON
--quiet, -q           # Output data only (no envelope)
--md                  # Output as Markdown
--agent               # Agent mode (JSON + quiet + no prompts)
--jq <filter>         # Apply jq filter to JSON output
--config <path>       # 使用指定配置文件
--profile <name>      # 使用指定配置
--json                # 输出 JSON 格式
--quiet, -q           # 仅输出数据(无封装结构)
--md                  # 输出 Markdown 格式
--agent               # Agent 模式(JSON + 静默输出 + 无提示)
--jq <filter>         # 对 JSON 输出应用 jq 过滤器

Error Handling

错误处理

bash
jsn auth status                           # Check authentication
jsn instance info                         # Check connectivity
Common errors:
  • Auth error →
    jsn auth login
  • Not found → Verify sys_id or table name
  • Forbidden → Check user roles/permissions
bash
jsn auth status                           # 检查鉴权状态
jsn instance info                         # 检查连通性
常见错误:
  • 鉴权错误 → 执行
    jsn auth login
  • 资源不存在 → 验证 sys_id 或表名是否正确
  • 访问被禁止 → 检查用户角色/权限

System Tables Reference

系统表参考

AreaTables
Tables
sys_db_object
,
sys_dictionary
Choices
sys_choice
Business Rules
sys_script
Script Includes
sys_script_include
Flows
sys_hub_flow
ACLs
sys_security_acl
Update Sets
sys_update_set
UI Policies
sys_ui_policy
Client Scripts
sys_script_client
Forms
sys_ui_section
,
sys_ui_element
Jobs
sysauto_script
,
sys_trigger
Logs
syslog
Service Portal
sp_portal
,
sp_widget
,
sp_page
Service Catalog
sc_cat_item
,
item_option_new
,
question_choice
,
sc_item_option_mtom
模块表名
sys_db_object
,
sys_dictionary
选项值
sys_choice
业务规则
sys_script
Script Includes
sys_script_include
流程
sys_hub_flow
ACLs
sys_security_acl
更新集
sys_update_set
UI 策略
sys_ui_policy
客户端脚本
sys_script_client
表单
sys_ui_section
,
sys_ui_element
作业
sysauto_script
,
sys_trigger
日志
syslog
服务门户
sp_portal
,
sp_widget
,
sp_page
服务目录
sc_cat_item
,
item_option_new
,
question_choice
,
sc_item_option_mtom