Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

BLOG - ServiceNow CartJS : Automate Laptop Requests

yelugusriharsha
Tera Contributor

Use Case:
When a new employee joins the organization, the IT department need to provide them with a laptop. Instead of doing this manually each time —the IT member should navigate to the Service Catalog, select the laptop item, fill in the details, and submit the request.

But what if ServiceNow could do this automatically the moment a new user is created?

In this article, I’ll walk u through how to automate laptop provisioning using:

  • A Business Rule

  • A Script Include

  • The sn_sc.CartJS() API

🎯 Use Case Overview

Use Case:
Whenever a new employee joins the organization, ServiceNow should automatically create a laptop request for them.

This ensures:

  • No onboarding delays

  • No manual catalog submissions

  • No missed hardware provisioning

🔑 Key Points of the Automation

1. Fully Automated Laptop Provisioning

As soon as a new user record is created (e.g., by HR ), ServiceNow automatically submits a laptop request on their behalf.

 

2. Uses the CartJS API

CartJS lets developers interact with the Service Catalog programmatically — adding items, setting variable values, and checking out the cart.

 

3. Script Include Handles the Cart Operations

The entire catalog logic (add item → set variables → checkout) is written once and reused.

 

4.Business Rule Detects User Creation

When a user is inserted, the Business Rule triggers the Script Include to start the provisioning workflow.

Understanding the sn_sc.CartJS() API

In ServiceNow, sn_sc.CartJS() is a powerful API that helps automate the management of catalog items within the Service Catalog.
Normally, users manually pick an item, fill in variables, and submit the request. With CartJS, all of this can be automated.

What CartJS Can Do

  • Add catalog items to the cart

  • Set variable values

  • Submit (checkout) the cart

  • Automatically generate:

    • REQ – Request

    • RITM – Request Item

    • CTASK – Catalog Tasks

🚀 Why CartJS Is Important

✔ Automating Catalog Item Creation

Perfect for use cases like onboarding, where items need to be requested automatically without user input.

✔ Pre-Filling Catalog Variables

Variables can be dynamically populated based on user data, roles, department, or custom logic.

✔ Integrating Complex Workflows

CartJS simplifies integration with processes like:

  • Asset Management

  • HR Onboarding

  • Incident Management

  • Approval Workflows

Using CartJS ensures accuracy, saves time, and reduces human error.

Script Include: LaptopProvisioningCart

This Script Include contains the logic for adding the laptop item to the cart and checking it out.

yelugusriharsha_0-1763635819136.png

 

What It Does

  • Loads the user

  • Creates a CartJS instance

  • Defines the laptop catalog item

  • Sets software variables automatically

  • Adds the item to the cart

  • Submits the cart (checkout)

  • Returns the created REQ number

Business Rule: Automatically Create Laptop Request

This Business Rule contains the logic for Automatically Create Laptop Request for New Users

yelugusriharsha_1-1763636010721.png

What it Does 

  • Detect new user creation

  • Call the Script Include

  • Fetch the request number (REQ)

  • Display confirmation

 

Automation Result : 

yelugusriharsha_3-1763636637433.png

yelugusriharsha_4-1763636881722.png

yelugusriharsha_5-1763636927321.png

yelugusriharsha_6-1763636970390.png

 

 

0 REPLIES 0