RITM Created but Variables Not Populating

NikhilJosht4U
Tera Contributor

I'm creating RITMs using a scheduled job that processes entries from a staging table.

The RITM gets created, but no variables are visible in the "Item Variables" tab. All variable values are present in the payload and mapped correctly.

Any idea why variables aren't showing up in the RITM?

4 REPLIES 4

Laveena-Agarwal
Kilo Sage

Hi @NikhilJosht4U 

Share the screenshots of scripts and output.

// Creating RITM using CartJS
var cart = new CartJS();
var item = cart.addItem('cat_item_sys_id'); 

item.setVariable('requested_for', requester_sys_id);
item.setVariable('requester_name', requester_sys_id);
item.setVariable('openned_by', requester_sys_id);
.
.
.
item.setVariable('additional', additional_urls);
item.setVariable('action', action);

var requestSysId = cart.placeOrder();


When single payload of data is sent, it works. But when huge amount of data is being sent, It doesnt capture the values but creates a RITM

Hi @NikhilJosht4U 

Huge amount meaning? are you talking about multiple RITMs ?

Try to use  script in the below format instead of using setVariable, create an object (newItem)

 

var cart = new sn_sc.CartJS();

var newItem = {

    "sysparm_id": "48ef0e6e2bca12d444a0f1996e91bf30", // Catalog Item ID

    "sysparm_quantity": "1",

    "variables": {          //Below are variables and their values

        "configuration_item": ci.toString(), // Passing CI sys_id

        "requested_by": assignedTo.toString(), // Using assignedTo as the requester

        "recipient": assignedTo.toString(), // Assigning the ticket to the same user

        "short_description_new": shortDescription, // Custom short description

        "description": descriptionValue, // Detailed description for the request

        "serial_number": serialNumber.toString(),

        "device_name": deviceName.toString(),

        "model": model.toString(),

        "assigned_to_user": assignedToUser.toString(),

        "last_scan_user": lastScanUser.toString(),

        "last_scan_date": lastScanDate

    }

};

 

gs.log("New Item: " + JSON.stringify(newItem)); // Show the new item details

 

// Add the item to the cart and proceed to checkout

var cartDetails = cart.addToCart(newItem);

gs.log('Cart details added: ' + JSON.stringify(cartDetails)); // Show the cart details

 

// Proceed to checkout

var checkoutInfo = cart.checkoutCart();

 

 

// Now we use the request_id from checkoutInfo directly, no need to parse it as JSON

var requestId = checkoutInfo ? checkoutInfo.request_id : null;

gs.log('Newly created Request ID: ' + requestId); // Show the new REQ ID

 

Related Article - Understanding sn_sc.CartJS() in ServiceNow: Its Im... - ServiceNow Community

@NikhilJosht4U 

share the complete code.

Did you check in backend table (sc_item_option_mtom) is variables are getting associated to that RITM?

If not then those won't be shown in variable editor.

AnkurBawiskar_0-1755174964184.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader