You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Server-Side Components/Scheduled Jobs/Submit catalog item/README.md
+28-9Lines changed: 28 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,32 @@
1
-
# ServiceNow Script: Submit Catalog Item via Scheduled Job
1
+
# Submit catalog item (Scheduled Job)
2
2
3
-
This script demonstrates how to programmatically submit a ServiceNow **catalog item** using the `Cart` API. It is designed to be run as a **Background Script** or adapted into a **Scheduled Job**. The script includes error handling and logging, and can be extended to support additional use cases such as variable injection or duplicate request prevention.
3
+
This snippet demonstrates how to submit a Service Catalog item programmatically from server-side code using the `sn_sc.CartJS` API.
4
4
5
-
## 📜 Overview
5
+
## Purpose
6
+
7
+
Add an item to the Service Catalog cart with variables and perform checkout to create the request/req item records.
8
+
9
+
## Script behavior
10
+
11
+
- Creates a `sn_sc.CartJS()` cart instance.
12
+
- Calls `addToCart()` with `sysparm_id`, optional `sysparm_quantity`, optional `sysparm_requested_for`, and a `variables` object.
13
+
- Calls `checkoutCart()` to place the order.
14
+
- Logs success or error information using `gs.info`, `gs.warn`, and `gs.error`.
15
+
16
+
## Placeholders to replace
17
+
18
+
-`SYS_ID_OF_CAT_ITEM`: the `sys_id` of the Catalog Item (`sc_cat_item` record).
19
+
-`SYS_ID_OF_REQUESTED_FOR_USER`: (optional) the `sys_id` of the user to set as Requested For. Remove the property to default to the current user.
20
+
-`variable_name1`, `variable_name2`, `variable_nameN`:variable names expected by the catalog item. Use the variable name (not label) unless your instance expects variable IDs.
21
+
22
+
## Expected returns
23
+
24
+
You will receive an object containing the request number representating of the created `sc_request` with a `sc_req_item` Item. If unsure, log `JSON.stringify(checkoutInfo)` to inspect.
25
+
26
+
## Overview
27
+
1.Creates a cart instance with sn_sc.CartJS</br>
28
+
2.Adds a catalog item to the cart</br>
29
+
3.Places the order (checkout)</br>
30
+
4.Logs success or error messages
6
31
7
-
This script performs the following actions:
8
32
9
-
1. Generates a unique cart ID.
10
-
2. Creates a new cart using the `Cart` API.
11
-
3. Adds a catalog item to the cart (no variables required).
0 commit comments