关于 rpa-bot-generation
面向 ServiceNow RPA Hub 使用者的技能,可将自然语言流程描述转化为机器人定义与动作,并配置触发器、凭据和执行监控。适用于自动化重复任务及缺少 API 的目标系统交互。
主要功能
- 01将流程描述转为机器人定义
- 02配置 UI 自动化与数据处理动作
- 03设置流程、计划或事件触发器
- 04配置凭据管理与机器人组
- 05查询执行记录并跟踪故障
适用场景
- 01自动录入跨桌面应用的数据
- 02连接缺少 API 的旧系统
- 03按 ServiceNow 流程或计划启动机器人
- 04监控机器人执行及失败情况
MCP 相关
示例使用 MCP 工具创建 ServiceNow RPA 流程、机器人、动作、触发器和凭据,并查询执行记录及分析数据。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ happy-technologies-llc/ happy-platform-skills --skill rpa-bot-generation安装后在 Claude Code 中输入/rpa-bot-generation确认已加载。
详细介绍
RPA 机器人生成
概述
此技能可根据自然语言描述的流程,在 ServiceNow RPA Hub 中生成机器人流程自动化(RPA)机器人。涵盖:
- 将业务流程描述转换为结构化的机器人定义
- 创建用于 UI 自动化、数据提取和系统交互的机器人操作
- 配置触发器,以便从 ServiceNow 工作流、计划或事件启动机器人
- 实施错误处理策略,包括重试逻辑、异常捕获和回退路径
- 安全管理机器人访问目标应用程序所需的凭据
- 将机器人组织到机器人组中,以分配工作负载并实现高可用性
- 通过性能分析和故障跟踪监控机器人执行情况
适用场景:
- 自动化流程挖掘中发现的重复性手动流程
- 构建机器人,连接缺少 API 的旧版系统
- 目标应用程序没有可用的 ServiceNow Integration Hub spoke 时
- 自动化桌面应用程序中的数据录入、提取或验证
- 为助手协作的自动化场景创建有人值守的机器人
前提条件
- 角色:
sn_rpa.admin、sn_rpa.designer、sn_rpa.operator或admin - 插件:
com.sn_rpa(RPA Hub)、com.sn_rpa.designer(RPA Desktop Design Studio) - 访问权限: 对 sn_rpa_bot、sn_rpa_action、sn_rpa_process 表具有读写权限
- 知识: 了解 RPA 概念(有人值守与无人值守机器人、选择器、录制)、目标应用程序 UI 结构,以及组织的自动化治理框架
- 基础设施: 已配置并安装 ServiceNow RPA agent 的 RPA 机器人机器
关键 RPA 表
| 表 | 用途 | 关键字段 |
|---|---|---|
sn_rpa_bot | 机器人定义 | name、description、state、bot_type、process、version、owner、robot_group |
sn_rpa_action | 单个机器人操作/步骤 | bot、action_type、order、name、target_application、selector、input_data、output_variable、error_handling |
sn_rpa_process | 业务流程定义 | name、description、category、owner、state、estimated_savings、complexity |
sn_rpa_credential | 凭据保险库条目 | name、application、credential_type、username、vault_id、rotation_policy |
sn_rpa_trigger | 机器人执行触发器 | bot、trigger_type、schedule、flow、event、condition |
sn_rpa_execution | 机器人执行日志 | bot、state、start_time、end_time、duration、status、error_message、robot、transactions_processed |
sn_rpa_robot_group | 机器人分组 | name、description、robots、max_concurrent、priority |
操作步骤
步骤 1:分析流程描述
解析用户的流程描述,确定:
- 流程范围: 机器人应端到端自动化的内容
- 目标应用程序: 机器人将与哪些系统交互
- 输入数据: 机器人启动所需的数据(电子表格、记录、队列)
- 操作: 按顺序执行的步骤(单击、输入、读取、导航、提取、验证)
- 输出: 机器人生成的内容(更新后的记录、报告、确认信息)
- 异常: 已知的错误场景和预期处理方式
步骤 2:创建流程定义
在 RPA Hub 中注册业务流程。
使用 MCP(Claude Code/Desktop):
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_process
fields:
name: "Invoice Data Entry Automation"
description: "Automates entry of approved invoice data from ServiceNow into the legacy ERP system. Process handles single invoice entry including vendor lookup, line item entry, and approval submission."
category: finance
owner: [process_owner_sys_id]
state: design
estimated_savings: 2400
complexity: medium
manual_steps: 15
avg_manual_time_minutes: 12
volume_per_month: 200
使用 REST API:
POST /api/now/table/sn_rpa_process
Content-Type: application/json
{
"name": "Invoice Data Entry Automation",
"description": "Automates entry of approved invoice data from ServiceNow into the legacy ERP system.",
"category": "finance",
"owner": "[process_owner_sys_id]",
"state": "design",
"estimated_savings": "2400",
"complexity": "medium"
}
步骤 3:创建机器人定义
定义与该流程关联的机器人。
使用 MCP:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_bot
fields:
name: "Invoice Entry Bot"
description: "Unattended bot that enters approved invoices into the legacy ERP system"
state: draft
bot_type: unattended
process: [process_sys_id]
version: "1.0"
owner: [bot_owner_sys_id]
robot_group: [robot_group_sys_id]
max_retries: 3
timeout_minutes: 30
使用 REST API:
POST /api/now/table/sn_rpa_bot
Content-Type: application/json
{
"name": "Invoice Entry Bot",
"description": "Unattended bot for legacy ERP invoice entry",
"state": "draft",
"bot_type": "unattended",
"process": "[process_sys_id]",
"version": "1.0",
"max_retries": "3",
"timeout_minutes": "30"
}
步骤 4:定义机器人操作
创建组成机器人工作流的顺序操作。
操作 1:打开目标应用程序:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_action
fields:
bot: [bot_sys_id]
action_type: open_application
order: 100
name: "Launch ERP Application"
target_application: "SAP GUI"
input_data: '{"executable_path": "C:\\Program Files\\SAP\\SAPgui\\saplogon.exe", "connection": "PRD"}'
timeout_seconds: 30
error_handling: retry
retry_count: 2
操作 2:使用托管凭据登录:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_action
fields:
bot: [bot_sys_id]
action_type: credential_login
order: 200
name: "Login to ERP"
credential: [credential_sys_id]
selector: '{"username_field": "#txtUser", "password_field": "#txtPassword", "login_button": "#btnLogin"}'
timeout_seconds: 15
error_handling: fail
error_message: "ERP login failed - check credentials in vault"
操作 3:导航并输入数据:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_action
fields:
bot: [bot_sys_id]
action_type: data_entry
order: 300
name: "Enter Invoice Header"
target_application: "SAP GUI"
input_data: |
{
"transaction": "FB60",
"fields": {
"vendor": "{invoice.vendor_number}",
"invoice_date": "{invoice.invoice_date}",
"posting_date": "{invoice.posting_date}",
"amount": "{invoice.total_amount}",
"currency": "{invoice.currency}",
"reference": "{invoice.sn_number}"
}
}
timeout_seconds: 20
error_handling: screenshot_and_fail
操作 4:验证并提交:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_action
fields:
bot: [bot_sys_id]
action_type: validation
order: 400
name: "Validate Entry and Submit"
input_data: |
{
"validation_checks": [
{"field": "status_bar", "expected": "Document posted", "selector": "#statusBar"},
{"field": "document_number", "not_empty": true, "selector": "#docNumber"}
],
"on_success": "capture_document_number",
"on_failure": "screenshot_and_rollback"
}
output_variable: erp_document_number
timeout_seconds: 15
操作 5:更新 ServiceNow 记录:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_action
fields:
bot: [bot_sys_id]
action_type: servicenow_update
order: 500
name: "Update Invoice Record in ServiceNow"
input_data: |
{
"table": "ap_invoice",
"sys_id": "{invoice.sys_id}",
"fields": {
"erp_reference": "{erp_document_number}",
"state": "posted",
"work_notes": "Bot: Invoice posted to ERP. Document: {erp_document_number}"
}
}
步骤 5:配置凭据管理
为机器人身份验证设置安全的凭据存储。
使用 MCP:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_credential
fields:
name: "ERP Service Account - Invoice Bot"
application: "SAP ERP"
credential_type: username_password
username: svc_rpa_invoice
vault_id: [credential_vault_id]
rotation_policy: 90_days
owner: [security_team_sys_id]
步骤 6:设置 Bot 触发器
配置 Bot 的执行时间和方式。
使用 MCP:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_trigger
fields:
bot: [bot_sys_id]
trigger_type: flow
flow: [flow_sys_id]
condition: "invoice.state == 'approved' && invoice.erp_reference == ''"
description: "Trigger bot when invoice is approved and not yet posted to ERP"
active: true
priority: normal
基于计划的触发器:
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_trigger
fields:
bot: [bot_sys_id]
trigger_type: schedule
schedule: "0 */2 * * 1-5"
description: "Run every 2 hours on weekdays to process queued invoices"
active: true
max_batch_size: 50
步骤 7:监控 Bot 执行情况
查询执行日志,以跟踪性能和错误。
使用 MCP:
Tool: SN-Query-Table
Parameters:
table_name: sn_rpa_execution
query: bot=[bot_sys_id]^ORDERBYDESCstart_time
fields: sys_id,bot,state,start_time,end_time,duration,status,error_message,robot,transactions_processed
limit: 50
生成执行分析:
Tool: SN-Execute-Background-Script
Parameters:
script: |
var analytics = {
period: 'Last 30 days',
total_executions: 0,
successful: 0,
failed: 0,
avg_duration_seconds: 0,
total_transactions: 0,
success_rate: 0,
common_errors: {},
time_saved_hours: 0
};
var ga = new GlideAggregate('sn_rpa_execution');
ga.addQuery('start_time', '>=', gs.daysAgo(30));
ga.addAggregate('COUNT');
ga.addAggregate('AVG', 'duration');
ga.addAggregate('SUM', 'transactions_processed');
ga.query();
if (ga.next()) {
analytics.total_executions = parseInt(ga.getAggregate('COUNT'));
analytics.avg_duration_seconds = Math.round(parseFloat(ga.getAggregate('AVG', 'duration')) || 0);
analytics.total_transactions = parseInt(ga.getAggregate('SUM', 'transactions_processed')) || 0;
}
var success = new GlideAggregate('sn_rpa_execution');
success.addQuery('start_time', '>=', gs.daysAgo(30));
success.addQuery('status', 'success');
success.addAggregate('COUNT');
success.query();
if (success.next()) {
analytics.successful = parseInt(success.getAggregate('COUNT'));
if (analytics.total_executions > 0)
analytics.success_rate = Math.round((analytics.successful / analytics.total_executions) * 100);
}
analytics.failed = analytics.total_executions - analytics.successful;
// Estimate time saved (12 min manual per transaction)
analytics.time_saved_hours = Math.round((analytics.total_transactions * 12) / 60);
gs.info('RPA EXECUTION ANALYTICS:\n' + JSON.stringify(analytics, null, 2));
description: "RPA: Generate bot execution analytics for last 30 days"
工具用法
| 操作 | MCP 工具 | REST 端点 |
|---|---|---|
| 创建流程 | SN-Create-Record | POST /api/now/table/sn_rpa_process |
| 创建 Bot | SN-Create-Record | POST /api/now/table/sn_rpa_bot |
| 创建操作 | SN-Create-Record | POST /api/now/table/sn_rpa_action |
| 创建触发器 | SN-Create-Record | POST /api/now/table/sn_rpa_trigger |
| 查询执行记录 | SN-Query-Table | GET /api/now/table/sn_rpa_execution |
| 管理凭据 | SN-Create-Record | POST /api/now/table/sn_rpa_credential |
| 分析 | SN-Execute-Background-Script | POST /api/now/table/sys_trigger |
最佳实践
- 先梳理流程: 构建 Bot 前,务必完整记录人工处理流程;对流程理解不足是 Bot 失败的首要原因
- 模块化操作: 将 Bot 拆分为小型、可复用的操作;不要创建包含 100 多个步骤的庞大 Bot
- 错误截图: 配置在每个关键操作失败时截取屏幕截图,以便调试
- 凭据轮换: 使用支持自动轮换的凭据库;切勿在 Bot 定义中硬编码密码
- 幂等性: 将 Bot 设计为可安全重复运行;处理前检查工作是否已完成
- 节流: 在操作之间添加延迟,避免给目标应用造成过大负载;遵守速率限制
- 机器人组: 对于高流量流程,将工作负载分配给多个机器人
- 监控告警: 为 Bot 故障设置通知,尤其是对业务关键流程
- 版本控制: 每次更改都递增 Bot 版本;保留回滚能力
- 人工参与: 对于高风险流程(财务、合规),在最终提交前添加人工审批步骤
故障排除
Bot 无法启动目标应用
症状: 第一个操作失败,并显示“找不到应用”或“超时” 原因: 机器人计算机未安装目标应用,或路径不正确 解决方案: 验证机器人计算机上的可执行文件路径。检查 RPA Agent 服务是否正在运行。确保机器人用户有权启动该应用。
找不到选择器错误
症状: Bot 无法定位目标应用中的 UI 元素 原因: 应用 UI 已更改(更新、补丁或动态元素 ID) 解决方案: 使用 RPA Desktop Design Studio 重新录制选择器。优先使用稳定的选择器(name、automationId),而非动态选择器(runtime IDs)。在与元素交互前添加等待条件。
凭据库访问被拒绝
症状: Bot 无法从凭据库获取凭据
原因: 机器人服务帐户没有凭据库访问权限,或凭据记录未激活
解决方案: 验证机器人的服务帐户是否具有 sn_rpa.credential_user 角色。检查凭据记录的状态是否为激活,并确认其已分配给正确的机器人组。
Bot 执行队列积压
症状: Bot 执行任务已进入队列,但未开始
原因: 组内所有机器人都处于忙碌、离线状态,或已达到最大并发执行限制
解决方案: 在 sn_rpa_robot_group 中检查机器人是否可用。如果资源允许,增大 max_concurrent。向组中添加更多机器人以进行水平扩展。
示例
示例 1:员工入职 Bot
场景: 自动化在 3 个系统中创建新员工帐户
流程定义:
- 输入:来自 ServiceNow 的已批准 HR 入职申请
- 步骤 1:创建 Active Directory 帐户
- 步骤 2:在 Exchange 中创建电子邮件邮箱
- 步骤 3:在旧版 HR 系统中配置访问权限
- 步骤 4:将 ServiceNow 入职任务更新为已完成
示例 2:报告生成机器人
场景: 从旧版系统生成并分发每周合规报告
Tool: SN-Create-Record
Parameters:
table_name: sn_rpa_bot
fields:
name: "Weekly Compliance Report Bot"
description: "Logs into compliance portal, generates report, downloads PDF, attaches to ServiceNow task"
bot_type: unattended
state: draft
version: "1.0"
触发条件: 每周一上午 6:00 定时触发
相关技能
genai/flow-generation- 用于协调 RPA 与其他自动化的 Flow Designergenai/playbook-generation- 可触发机器人的流程自动化 playbookgenai/spoke-generation- Integration Hub spokes,作为以 API 为先的 RPA 替代方案admin/workflow-creation- 与 RPA 触发器集成的工作流development/scheduled-jobs- 安排机器人执行任务