A background script that programmatically creates ServiceNow Service Catalog items with form variables. Define your catalog item as a config object and run it - no clicking through the UI.
- Creates a catalog item with name, description, category, catalog, and workflow
- Creates all form variables (text fields, dropdowns, reference fields, date pickers, etc.)
- Creates dropdown choices for select/multi-select fields
- Logs the sys_id and a direct link to the new item
- Open your ServiceNow instance
- Navigate to Scripts - Background
- Paste the script
- Edit the
configobject at the top with your catalog item details and variables - Run it
| Type | Description |
|---|---|
string |
Single-line text |
text |
Multi-line text |
integer |
Number |
boolean |
Yes/No checkbox |
checkbox |
Checkbox |
date |
Date picker |
datetime |
Date/Time picker |
email |
Email field |
url |
URL field |
phone |
Phone number |
reference |
Reference to another table |
select |
Dropdown (single choice) |
multi_select |
Multi-select dropdown |
label |
Read-only label / section divider |
break |
Container break |
macro |
UI Macro |
Each variable supports these optional properties:
{
name: 'field_name', // Internal name
label: 'Display Label', // Label shown on the form
type: 'string', // One of the types above
mandatory: true, // Required field
default_value: 'value', // Default value
help_text: 'Tooltip text', // Help text / tooltip
order: 100, // Display order
reference: 'sys_user', // Table name (for reference type)
reference_qualifier: 'active=true', // Encoded query filter (for reference type)
choices: [ // For select / multi_select types
{ value: 'opt1', label: 'Option 1' },
{ value: 'opt2', label: 'Option 2' }
]
}The script includes a sample config that creates a request form with a user reference field, an access level dropdown, and a business justification text area. Modify it to fit your needs.
- The script looks up catalog, category, and workflow by name. If not found, it logs a warning and continues.
- Variables are created in the order specified by the
orderproperty. - The script is safe to run multiple times, but it will create duplicate items - delete the old one first if re-running.