mcpField
C
catalog-item-generation

catalog-item-generation

github.com/happy-technologies-llc开发4141 次安装2 天前更新
代码仓库

关于 catalog-item-generation

catalog-item-generation 是一项 ServiceNow 技能,可将自然语言服务描述转为配置完整的目录项目,面向服务负责人,涵盖变量、分类、审批和履行设置。

主要功能

  1. 01根据描述生成目录项目
  2. 02创建变量和选项
  3. 03将项目归入目录分类
  4. 04配置审批规则和工作流
  5. 05设置变量集与动态表单
  6. 06验证并启用目录项目

适用场景

  1. 01根据服务描述构建申请表
  2. 02按项目成本添加审批步骤
  3. 03批量创建多个目录项目

MCP 相关

该技能通过 ServiceNow MCP 工具查询表、创建和更新记录、搜索类似项目、检查架构并运行后台脚本。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/happy-technologies-llc/happy-platform-skills --skill catalog-item-generation

安装后在 Claude Code 中输入/catalog-item-generation确认已加载。

详细介绍

目录项生成

概述

此技能可根据自然语言描述生成完整的服务目录项。它涵盖:

  • 根据纯文本描述,在 sc_cat_item 中创建包含所有必填字段的目录项
  • 根据目录项要求,在 item_option_new 中生成目录变量(问题/字段)
  • 通过 sc_category 和 sc_cat_item_category 将目录项分配到类别
  • 为目录项配置审批规则和工作流
  • 设置变量集、UI 策略和客户端脚本,实现动态表单行为
  • 将目录项发布到特定目录和类别,供最终用户访问

适用场景: 服务负责人用通俗语言描述新的目录服务项目,并希望将其转化为配置完整的 ServiceNow 目录项,包括变量、审批和履行规则时。

价值: 将目录项的创建时间从数小时缩短到数分钟,确保变量命名和配置一致,并自动应用组织的审批和履行标准。

前提条件

  • 插件: com.glideapp.servicecatalog(Service Catalog)
  • 角色: catalog_admin、catalog_manager 或 admin
  • 访问权限: 对 sc_cat_item、sc_category、sc_cat_item_category、item_option_new 和工作流表具有读写权限
  • 知识: 了解所在组织的目录结构、审批政策和履行团队

操作步骤

第 1 步:分析自然语言描述

解析用户的描述,识别目录项的组成部分:

组成部分提取内容示例
目录项名称简短、明确的标题“新笔记本电脑申请”
描述对服务项目的详细说明“申请一台符合规格要求的新笔记本电脑”
类别目录项所属位置“硬件申请”
变量申请人需要填写的问题/字段型号、内存、存储空间、业务理由
审批必须批准的人员经理、金额超过 $2000 时由 IT 总监审批
履行负责处理申请的人员“硬件团队”分配组
定价费用或定价模式基础价格 $1200,因型号而异
第 2 步:查找或创建目标类别

查询现有类别,以便正确放置目录项。

使用 MCP(Claude Code/Desktop):

Tool: SN-Query-Table
Parameters:
  table_name: sc_category
  query: active=true^titleLIKEHardware
  fields: sys_id,title,description,parent,sc_catalog,active,icon
  limit: 10

使用 REST API:

GET /api/now/table/sc_category?sysparm_query=active=true^titleLIKEHardware&sysparm_fields=sys_id,title,description,parent,sc_catalog,active,icon&sysparm_limit=10&sysparm_display_value=true

如有需要,创建新类别:

Tool: SN-Create-Record
Parameters:
  table_name: sc_category
  fields:
    title: "Hardware Requests"
    description: "Request new hardware including laptops, monitors, peripherals, and accessories"
    sc_catalog: [catalog_sys_id]
    parent: [parent_category_sys_id]
    active: true
    icon: "hardware-laptop"
第 3 步:创建目录项

生成包含所有核心字段的目录项记录。

使用 MCP:

Tool: SN-Create-Record
Parameters:
  table_name: sc_cat_item
  fields:
    name: "New Laptop Request"
    short_description: "Request a new laptop with your preferred specifications"
    description: |
      Use this form to request a new laptop computer. Select your preferred model,
      specifications, and provide business justification. Requests over $2,000 require
      IT Director approval.

      **Included with all laptops:**
      - Standard software image
      - 3-year warranty
      - Docking station and power adapter

      **Expected delivery:** 5-10 business days after approval
    category: [category_sys_id]
    sc_catalogs: [catalog_sys_id]
    active: true
    availability: on_desktop
    type: item
    fulfillment_group: [hardware_team_sys_id]
    delivery_time: "2026-03-19 08:00:00"
    price: 1200
    recurring_price: 0
    order: 100
    icon: "hardware-laptop"
    mandatory_attachment: false
    request_method: order_guide

使用 REST API:

POST /api/now/table/sc_cat_item
Content-Type: application/json

{
  "name": "New Laptop Request",
  "short_description": "Request a new laptop with your preferred specifications",
  "description": "Use this form to request a new laptop computer...",
  "category": "[category_sys_id]",
  "sc_catalogs": "[catalog_sys_id]",
  "active": "true",
  "type": "item",
  "fulfillment_group": "[hardware_team_sys_id]",
  "price": "1200",
  "order": "100"
}
第 4 步:生成目录变量

创建申请人需要填写的表单变量(问题)。

使用 MCP:

Tool: SN-Create-Record
Parameters:
  table_name: item_option_new
  fields:
    cat_item: [cat_item_sys_id]
    name: "laptop_model"
    question_text: "Laptop Model"
    type: 3
    choice_table: ""
    default_value: "standard"
    mandatory: true
    order: 100
    tooltip: "Select the laptop model that best fits your work requirements"

变量类型参考:

类型代码类型名称用途
1是/否布尔选择
2多行文本长篇描述、理由
3多项选择下拉选择
5选择框多选选项
6单行文本简短文本输入
7复选框切换选项
8引用链接到另一条表记录
9日期日期选择器
10日期/时间日期和时间选择器
14宏仅显示信息
21列表收集器多重引用选择
24掩码敏感信息输入

为完整表单创建多个变量:

Tool: SN-Execute-Background-Script
Parameters:
  description: Create catalog item variables for laptop request
  script: |
    var itemId = '[cat_item_sys_id]';
    var variables = [
      { name: 'laptop_model', question_text: 'Laptop Model', type: 3, mandatory: true, order: 100, tooltip: 'Select your preferred model' },
      { name: 'ram_size', question_text: 'RAM (Memory)', type: 3, mandatory: true, order: 200, default_value: '16gb' },
      { name: 'storage_size', question_text: 'Storage', type: 3, mandatory: true, order: 300, default_value: '512gb' },
      { name: 'additional_software', question_text: 'Additional Software Required', type: 2, mandatory: false, order: 400 },
      { name: 'business_justification', question_text: 'Business Justification', type: 2, mandatory: true, order: 500, tooltip: 'Explain why this laptop is needed' },
      { name: 'needed_by_date', question_text: 'Date Needed By', type: 9, mandatory: false, order: 600 },
      { name: 'replace_existing', question_text: 'Is this replacing an existing laptop?', type: 1, mandatory: true, order: 700, default_value: 'false' },
      { name: 'existing_asset_tag', question_text: 'Existing Asset Tag', type: 6, mandatory: false, order: 800, tooltip: 'Enter asset tag of laptop being replaced' }
    ];

    variables.forEach(function(v) {
      var gr = new GlideRecord('item_option_new');
      gr.initialize();
      gr.cat_item = itemId;
      gr.name = v.name;
      gr.question_text = v.question_text;
      gr.type = v.type;
      gr.mandatory = v.mandatory || false;
      gr.order = v.order;
      if (v.default_value) gr.default_value = v.default_value;
      if (v.tooltip) gr.tooltip = v.tooltip;
      gr.active = true;
      gr.insert();
    });

    gs.info('Created ' + variables.length + ' variables for catalog item');

为多项选择变量添加选项:

Tool: SN-Execute-Background-Script
Parameters:
  description: Create choices for laptop model variable
  script: |
    var choices = [
      { text: 'Standard (Dell Latitude 5540)', value: 'standard', price: 1200, order: 100 },
      { text: 'Performance (Dell Latitude 7640)', value: 'performance', price: 1800, order: 200 },
      { text: 'Developer (MacBook Pro 14")', value: 'developer', price: 2400, order: 300 },
      { text: 'Executive (MacBook Pro 16")', value: 'executive', price: 3200, order: 400 }
    ];

    choices.forEach(function(c) {
      var gr = new GlideRecord('question_choice');
      gr.initialize();
      gr.question = '[laptop_model_var_sys_id]';
      gr.text = c.text;
      gr.value = c.value;
      gr.price = c.price || 0;
      gr.order = c.order;
      gr.inactive = false;
      gr.insert();
    });

    gs.info('Created ' + choices.length + ' choices for laptop model');
第 5 步:配置审批规则

根据目录项费用或其他条件设置审批要求。

使用 MCP:

Tool: SN-Create-Record
Parameters:
  table_name: sysapproval_group
  fields:
    document_id: [cat_item_sys_id]
    assignment_group: [manager_approval_group_sys_id]
    approval_column: approval
    condition: "price>0"
    order: 100
    approval: requested

使用 REST API:

POST /api/now/table/sysapproval_group
Content-Type: application/json

{
  "document_id": "[cat_item_sys_id]",
  "assignment_group": "[manager_approval_group_sys_id]",
  "approval_column": "approval",
  "condition": "price>0",
  "order": "100"
}
第 6 步:将目录项关联到类别

创建目录项与类别的关联,以便在目录中导航。

使用 MCP:

Tool: SN-Create-Record
Parameters:
  table_name: sc_cat_item_category
  fields:
    sc_cat_item: [cat_item_sys_id]
    sc_category: [category_sys_id]

使用 REST API:

POST /api/now/table/sc_cat_item_category
Content-Type: application/json

{
  "sc_cat_item": "[cat_item_sys_id]",
  "sc_category": "[category_sys_id]"
}
第 7 步:验证并激活

发布前验证完整的目录项配置。

使用 MCP:

Tool: SN-Query-Table
Parameters:
  table_name: item_option_new
  query: cat_item=[cat_item_sys_id]^active=true
  fields: name,question_text,type,mandatory,order,default_value
  limit: 30
  order_by: order

通过目录 API 检查目录项:

GET /api/sn_sc/servicecatalog/items/[cat_item_sys_id]?sysparm_display_value=true

激活目录项:

Tool: SN-Update-Record
Parameters:
  table_name: sc_cat_item
  sys_id: [cat_item_sys_id]
  fields:
    active: true
    visible_standalone: true

工具用法

MCP 工具参考
工具使用场景
SN-Query-Table查询现有类别、条目、变量和审批
SN-Create-Record创建新条目、变量、选项、类别和审批规则
SN-Update-Record激活条目、更新配置
SN-Natural-Language-Search根据描述查找相似的现有条目或类别
SN-Discover-Table-Schema查看目录表的字段定义
SN-Execute-Background-Script批量创建变量、选项和复杂配置
REST API 参考
端点方法用途
/api/now/table/sc_cat_itemGET/POST/PATCH管理目录条目
/api/now/table/sc_categoryGET/POST管理目录类别
/api/now/table/sc_cat_item_categoryPOST将条目关联到类别
/api/now/table/item_option_newGET/POST创建和查询目录变量
/api/now/table/question_choicePOST为多选变量添加选项
/api/sn_sc/servicecatalog/itemsGET通过 Service Catalog API 验证条目

最佳实践

  • 命名保持一致: 所有条目的变量名称使用统一的命名规范(snake_case),问题文本使用统一的命名格式(标题式大小写)
  • 必须提供理由: 对于超过费用阈值的条目,始终添加业务理由变量
  • 限制变量数量: 表单变量数保持在 12 个以内;使用变量集对相关字段进行分组
  • 设置默认值: 预先填入常用选项,减少请求者的操作
  • 使用引用变量: 链接到现有表(例如,用于办公地点的 cmn_location),而不是使用自由文本
  • 发布前测试: 在非生产目录中验证条目,或在使其可见前设置 active=false
  • 记录履行说明: 在条目描述中包含清晰的履行说明,供分配组参考
  • 对目录条目进行版本管理: 使用条目的 meta 字段或工作备注,跟踪配置随时间的变更

故障排除

条目表单中未显示变量

原因: 变量的 cat_item 引用与条目的 sys_id 不匹配,或者变量未激活 解决方案: 使用 cat_item=[sys_id] 查询 item_option_new,验证关联关系。检查每个变量的 active=true。

目录中未显示条目

原因: 条目未激活、未关联到目录,或用户缺少查看该条目所需的角色/组 解决方案: 确认 active=true、已设置 sc_catalogs,并检查 sc_cat_item_user_criteria 中的访问限制。

未触发审批

原因: 审批规则条件不匹配,或者未为该条目配置审批组 解决方案: 检查该条目的 sysapproval_group 记录。验证请求的条件表达式是否计算为 true。

下拉菜单未显示选项

原因: question_choice 记录未关联到正确的变量 sys_id 解决方案: 使用 question=[variable_sys_id] 查询 question_choice,并确认 inactive=false。

示例

示例 1:根据描述生成条目

输入: “创建一个用于申请停车通行证的目录条目。员工应选择办公地点、停车类型(室内/室外)、车辆牌照和开始日期。需要经理审批。”

生成的条目:

  • 名称:“停车通行证申请”
  • 类别:“设施”
  • 变量:办公地点(引用)、停车类型(下拉菜单)、车牌(文本)、开始日期(日期)
  • 审批:经理审批
示例 2:软件许可证申请

输入: “需要一个申请软件许可证的表单。用户从列表中选择软件,填写许可证数量并提供理由。申请超过 10 个许可证时,需要 IT 总监审批。”

Tool: SN-Create-Record
Parameters:
  table_name: sc_cat_item
  fields:
    name: "Software License Request"
    short_description: "Request new or additional software licenses"
    category: [software_category_sys_id]
    sc_catalogs: [catalog_sys_id]
    active: true
    type: item
    fulfillment_group: [software_team_sys_id]
    order: 200
示例 3:批量创建项目

输入:“为 HR 类别创建 3 个项目:徽章补办($25)、办公桌搬迁(免费)和人体工学评估(免费)”

使用第 4 步中的批量后台脚本方法,在一次脚本执行中创建全部三个项目及其变量。

相关技能

  • catalog/variable-management - 高级变量配置和变量集
  • catalog/ui-policies - 根据变量值动态调整表单行为
  • catalog/approval-workflows - 复杂的审批路由和升级
  • catalog/item-creation - 标准项目创建流程
  • catalog/request-fulfillment - 履行工作流配置
  • catalog/multi-turn-ordering - 通过 Virtual Agent 进行对话式订购

评论

支持 Markdown