servicenow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJace'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:
- Choose the right output mode — when parsing data;
--jsonwhen presenting to humans--md - Use sys_id for updates — All update/delete operations require sys_id
- Check auth first — Run if commands fail
jsn auth status - Profile scope — Use or switch with
--profile <name>jsn config switch <name>
必须严格遵守以下规则:
- 选择合适的输出模式 — 解析数据时使用 ;向用户展示内容时使用
--json--md - 更新操作使用 sys_id — 所有更新/删除操作都需要提供 sys_id
- 优先检查授权 — 如果命令执行失败,先运行 检查授权状态
jsn auth status - 配置文件作用域 — 使用 指定配置,或通过
--profile <name>切换激活配置jsn config switch <name>
Output Modes
输出模式
| Goal | Flag | Format |
|---|---|---|
| Parse data, pipe to jq | | JSON envelope: |
| Show results to user | | Markdown tables |
| Automation/scripting | | JSON + quiet + no interactive prompts |
| Raw data only | | JSON data without envelope |
| 目标 | 参数 | 格式 |
|---|---|---|
| 解析数据,管道传输到 jq | | JSON 封装结构: |
| 向用户展示结果 | | Markdown 表格 |
| 自动化/脚本调用 | | JSON 格式 + 静默输出 + 无交互提示 |
| 仅输出原始数据 | | 无封装的纯 JSON 数据 |
JSON Envelope
JSON 封装结构
Every command supports :
--jsonjson
{
"ok": true,
"data": [...],
"summary": "5 tables",
"breadcrumbs": [
{"action": "show", "cmd": "jsn tables show incident", "description": "View details"}
]
}Breadcrumbs suggest next commands for navigation.
所有命令都支持 参数:
--jsonjson
{
"ok": true,
"data": [...],
"summary": "5 tables",
"breadcrumbs": [
{"action": "show", "cmd": "jsn tables show incident", "description": "View details"}
]
}面包屑字段会推荐下一步可执行的导航命令。
Quick Reference
快速参考
| Task | Command |
|---|---|
| List tables | |
| Show table schema | |
| List table columns | |
| Create table | |
| Add column to table | |
| Query records | |
| Show record | |
| Count records | |
| Create record | |
| Create with file | |
| Update record | |
| Delete record | |
| List business rules | |
| Show rule script | |
| List flows | |
| List script includes | |
| Show script code | |
| List ACLs | |
| List update sets | |
| Set current update set | |
| List choices | |
| List jobs | |
| Run job | |
| List forms | |
| Show list columns | |
| List list views | |
| List UI policies | |
| List client scripts | |
| List catalog items | |
| List item variables | |
| List variable choices | |
| Add variable choice | |
| Variable types | |
| Search docs | |
| Compare instances | |
| Generate code | |
| Run background script | |
| Run script from file | |
| 任务 | 命令 |
|---|---|
| 列出所有表 | |
| 查看表结构 | |
| 列出表字段 | |
| 创建表 | |
| 为表新增字段 | |
| 查询记录 | |
| 查看记录详情 | |
| 统计记录数量 | |
| 创建记录 | |
| 基于文件创建记录 | |
| 更新记录 | |
| 删除记录 | |
| 列出业务规则 | |
| 查看规则脚本 | |
| 列出流程 | |
| 列出 script includes | |
| 查看脚本代码 | |
| 列出 ACLs | |
| 列出更新集 | |
| 设置当前使用的更新集 | |
| 列出选项值 | |
| 列出作业 | |
| 运行作业 | |
| 列出表单 | |
| 查看列表字段 | |
| 列出列表视图 | |
| 列出 UI 策略 | |
| 列出客户端脚本 | |
| 列出目录项 | |
| 列出项变量 | |
| 列出变量选项值 | |
| 新增变量选项值 | |
| 查看变量类型 | |
| 搜索文档 | |
| 实例对比 | |
| 生成代码 | |
| 运行后台脚本 | |
| 运行文件内的脚本 | |
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_userbash
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_userRecords (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 variablesbash
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 scriptbash
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 detailsbash
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 codebash
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 coveragebash
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 parentbash
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 hundredsbash
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 hundredsJobs & 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 nowbash
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 scriptsbash
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 # Pagesbash
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 referenceNote: manages (field-level choices). Use for catalog variable dropdown choices ( table).
jsn choicessys_choicejsn variable choicesquestion_choicebash
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 choicessys_choicequestion_choicejsn variable choicesLogs
日志
bash
jsn logs --json # Recent logs
jsn logs --level error --json # Filter by level
jsn logs --source <name> --json # Filter by sourcebash
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 cachebash
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 ./schemabash
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 ./schemaRaw 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 APIsbash
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 # 自定义/作用域 APIBackground 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 outputEquivalent to "Scripts - Background" in the ServiceNow UI. Uses internally.
Use or to produce output. Full server-side API access (GlideRecord, gs, etc.).
sys.scripts.dogs.print()gs.info()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 中的「脚本 - 后台」,内部使用 实现。使用 或 生成输出,支持完整的服务端 API 访问(GlideRecord、gs 等)。
sys.scripts.dogs.print()gs.info()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 incidentbash
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 incidentConfiguration
配置
~/.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 profilebash
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 credentialsEnvironment variables:
- — Override stored token
SERVICENOW_TOKEN - — Override instance URL
SERVICENOW_INSTANCE
bash
jsn auth login # 交互式登录
jsn auth status # 检查鉴权状态
jsn auth logout # 清空凭证环境变量:
- — 覆盖本地存储的令牌
SERVICENOW_TOKEN - — 覆盖实例 URL
SERVICENOW_INSTANCE
Interactive Pickers
交互式选择器
Commands with arguments open pickers when omitted:
[optional]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 providedAlias: works as an alias for on all commands (e.g., , ).
getshowjsn records getjsn tables get带有 参数的命令在参数缺失时会自动打开选择器:
[可选]bash
jsn tables show [<name>] # 未提供名称时打开选择器
jsn rules show [<id>] # 未提供ID时打开选择器
jsn updateset use [<name>] # 未提供名称时打开选择器别名: 所有命令的 都可以用 作为别名(例如 、)。
showgetjsn records getjsn tables getGlobal 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 connectivityCommon 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
系统表参考
| Area | Tables |
|---|---|
| Tables | |
| Choices | |
| Business Rules | |
| Script Includes | |
| Flows | |
| ACLs | |
| Update Sets | |
| UI Policies | |
| Client Scripts | |
| Forms | |
| Jobs | |
| Logs | |
| Service Portal | |
| Service Catalog | |
| 模块 | 表名 |
|---|---|
| 表 | |
| 选项值 | |
| 业务规则 | |
| Script Includes | |
| 流程 | |
| ACLs | |
| 更新集 | |
| UI 策略 | |
| 客户端脚本 | |
| 表单 | |
| 作业 | |
| 日志 | |
| 服务门户 | |
| 服务目录 | |