Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ServiceNow Background Script – Create RITM via sn_sc.CartJS()

## Overview
This script demonstrates how to programmatically create a **Request Item (RITM)** and **Request (REQ)** in ServiceNow using the modern **`sn_sc.CartJS()` API**.

The script simulates a Service Catalog order submission — adding a catalog item to the cart and checking it out. This ensures that all **catalog flows, workflows, and business rules** are triggered exactly as if the request were placed through the Service Portal or native UI.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

var cart = new sn_sc.CartJS();
//define variables
var itemDetails = {
'sysparm_id': 'catalog_item_sys_id',
'variables': {
'requested_for': 'user_sys_id'
/*
.
.
remaining variables
.
.
*/
}
};

// Add item to cart (returns item sys_id within the cart)
var cartItem = cart.addToCart(itemDetails);
gs.info('Added catalog item to cart: ' + cartItem);

// -- Place the order ---
var order = cart.checkoutCart();
gs.info('Order placed successfully. Request Sys ID: ' + order.request_id);
Loading