--- title: CartJS - Scoped description: The CartJS API provides methods that enable you to access a user's shopping cart.Creates an instance of the CartJS class with the name of a defined cart for the user who is currently logged in.Adds the request for a catalog item to the current cart.Specifies if the current user has the required role to edit the Request for field.Performs the cart checkout. If the two-step checkout is enabled, returns the order summary. If the two-step checkout is disabled, the cart is submitted and details of the generated request are returned.Deletes the current cart.Returns the cart details.Returns the ID of the current cart.Returns a GlideRecord object containing records for items in the current cart.Returns the delivery address for the current cart.Returns the sys\_id of the user for whom the cart is requested.Returns the name of the user for whom the current cart is requested.Returns the special instructions for the current cart.Orders a single item. If two-step checkout is enabled, the method adds the specified item to the cart and returns the sys\_id of the cart. If two-step checkout is disabled, the method completes the purchase of the specified item and returns the sys\_id of the generated request.Sets the delivery address for the current cart.Sets the sys\_id in the sys\_user record of the user for whom the cart is requested.Sets the special instructions for the current cart.Updates special instructions, requested for, and delivery address from the request parameter and performs the cart checkout. Use this API to modify the mentioned parameters of the cart and perform the cart checkout simultaneously. Missing parameters in the request object will have their default value.Updates an item in the cart. locale: en-US canonical_url: https://www.servicenow.com/docs/r/australia/api-reference/server-api-reference/c\_CartJSScoped.html release: australia product: Server API Reference classification: server-api-reference topic_type: concept last_updated: "2026-03-12" reading_time_minutes: 9 breadcrumb: [Server API reference, API reference, API implementation and reference] --- # CartJS- Scoped The CartJS API provides methods that enable you to access a user's shopping cart. This API runs in the `sn_sc` namespace. The Service Catalog Scoped API plugin \(ID: com.glideapp.servicecatalog.scoped.api\) that is enabled by default is required to access the CartJS API. **Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md) ## CartJS - CartJS\(String cartName\) Creates an instance of the CartJS class with the name of a defined cart for the user who is currently logged in. |Name|Type|Description| |----|----|-----------| |cartName|String|Optional. Name of a defined cart for the user who is currently logged in.| ``` var cart = new sn_sc.CartJS(cart1); ``` ## CartJS - addToCart\(Map request\) Adds the request for a catalog item to the current cart.
| Name | Type | Description |
|---|---|---|
| request | Map | A JSON object that contains the details of the catalog item to be added to the cart.The structure of the request object is: ``` { 'sysparm_id': item_id, 'sysparm_quantity': item_quantity, 'variables':{ 'var_name': 'var_value', ... } } ``` - item\_id: sys\_id of the item to be added to the cart - item\_quantity: Number of items to be added. Default value is 1. - var\_name: Name of the question. - var\_value: Value of the answer \(Not the display value\). |
| Type | Description |
|---|---|
| JSON | Structure of the current cart.``` { 'subtotal': value, 'items':[ { itemName:'', quantity:'', price:'', recurring_price:'' } ...] } ``` |
| Type | Description |
|---|---|
| Boolean | Flag that indicates whether the user has the required role to edit the requested for field.Possible values: - true: User has the required role. - false: User does not have the required role. Data type: Boolean |
| Type | Description |
|---|---|
| JSON | If the two-step checkout is enabled, the summary of the items in the cart is returned.``` { "subtotal_price":"", "subtotal_recurring_frequency":"", "delivery_address":"", "special_instructions":"", "total_title":"", "requested_for_user":"System Administrator", "requested_for":"6816f79cc0a8016401c5a33be04be441", "daily": ["frequency_subtotal":"", "items":[{}, {}, ...], …], "monthly":["frequency_subtotal":"", "items":[{}, {}, ...], …], "annually":["frequency_subtotal":"", "items":[{}, {}, ...], …], "none":["frequency_subtotal":"", "items":[{}, {}, ...], …], } ``` If the two-step checkout is disabled: ``` { 'request_id' : "sys_id of the generated request", "request_number" : "Number of the generated request" } ``` |
| Type | Description |
|---|---|
| String | Sys\_id of the user record for whom the cart is requested.Table: User \[sys\_user\] |
| Type | Description |
|---|---|
| String | Name of the user for whom the current cart is requested.Table: User \[sys\_user\] |
| Name | Type | Description |
|---|---|---|
| request | Map | JSON object that contains details of the catalog item to order. |
| request.delivery\_address | String | Address to which to deliver the items.Default: Address of user |
| request.sysparm\_id | String | Required. The sys\_id of the item to purchase. |
| request.special\_instructions | String | Instructions to follow when processing the order. |
| request.sysparm\_quantity | String | Quantity of the specified item to purchase.Default: 1 |
| request.sysparm\_requested\_for | String | The sys\_id of the user for whom the item is requested.Default: Session user |
| request.variables | Array | Questions and customer answers associated with the item. |
| request.variables.var\_name | String | Name of the question. |
| request.variables.var\_value | String | Customer's response to the associated question. |
| Type | Description |
|---|---|
| JSON key/value pairs |
Output if two-step checkout is enabled:```
{
'cart_id' : ' |
| Name | Type | Description |
|---|---|---|
| request | Map | JSON object that contains details of the cart to be submitted. ``` { 'special_instructions': "String", 'requested_for': '"String", 'delivery_address': "String" } ``` |
| request.special\_instructions | String | Special instructions to include with the order. |
| request.requested\_for | String | Sys\_id of the user who the order is requested for.Default: The current user. Table: User \[sys\_user\] |
| request.delivery\_address | String | Delivery address for the order. |
| Type | Description |
|---|---|
| JSON | Structure of the cart.``` { 'request_id' : 'sys_id of the generated Request', 'request_number' : 'Number of the generated Request' } ``` |
| Name | Type | Description |
|---|---|---|
| request | Map | A JSON object that contains details of the catalog item to be updated.The structure of the request object is: ``` { 'sysparm_quantity' : item_quantity, 'sysparm_requested_for' : requested_for, 'variables' : { 'var_name' : 'var_value', ... } } ``` - item\_quantity: Number of items to be added. Default value is 1. - var\_name: Name of the question. - var\_value: Value of the answer \(Not the display value\). |
| cart\_item\_id | String | sys\_id of the cart item to be modified. |
| Type | Description |
|---|---|
| JSON | Details of the cart.``` { 'subtotal': value, 'items':[ { itemName:'', quantity:'', price:'', recurring_price:'' } ...], ... } ``` |