CartJS - Scoped
-
- UpdatedJan 30, 2025
- 7 minutes to read
- Yokohama
- API reference
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.
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. |
Example
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:
|
Type | Description |
---|---|
JSON | Structure of the current cart. |
Example
This example shows how you can add multiple items to the cart. Note that var cart =
new sn_sc.CartJS();
is inside the loop. You must call
sn_sc.CartJS()
multiple times to be able to add multiple items to the
cart.
Output
CartJS - canViewRF()
Specifies if the current user has the required role to edit the Request for field.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the user has the required role to edit the requested for field. Possible values:
Data type: Boolean |
Example
This background script code example shows how to check if the current user has the role needed to edit the requested for field.
Response:
CartJS - checkoutCart()
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.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
JSON | If the two-step checkout is enabled, the summary of the items in the cart is
returned. If
the two-step checkout is
disabled: |
Example
Output
CartJS - empty()
Deletes the current cart.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
void |
Example
CartJS - getCartDetails()
Returns the cart details.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | Object pointing to the current cart details. |
Example
Example:
Output:
CartJS - getCartID()
Returns the ID of the current cart.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Sys_id for the current cart. |
Example
Returns the sys_id of the current cart.
Output
CartJS - getCartItems()
Returns a GlideRecord object containing records for items in the current cart.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideRecord | GlideRecord object including records and fields from the Item [sc_cart_item] table that describe an item in the current cart. |
Example
Returns quantity and Catalog Item field values for items in the current cart.
Output
CartJS - getDeliveryAddress()
Returns the delivery address for the current cart.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Delivery address for the current cart. |
Example
Sets and then returns the delivery address for the current cart.
Output
CartJS - getRequestedFor()
Returns the sys_id of the user for whom the cart is requested.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Sys_id of the user record for whom the cart is requested. Table: User [sys_user] |
Example
Returns the user sys_id associated with the cart.
Output:
CartJS - getRequestedForDisplayName()
Returns the name of the user for whom the current cart is requested.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Name of the user for whom the current cart is requested. Table: User [sys_user] |
Example
Returns the name of the user associated with the cart.
Output:
CartJS - getSpecialInstructions()
Returns the special instructions for the current cart.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Special instructions for the current cart. |
Example
This example shows how to set and retrieve the special instructions for the current cart.
Output
CartJS - orderNow(Map request)
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.
Type | Description |
---|---|
JSON key/value pairs | Output if two-step checkout is
enabled: Output if two-step checkout is disabled: |
Example
Output
CartJS - setDeliveryAddress(String address)
Sets the delivery address for the current cart.
Name | Type | Description |
---|---|---|
address | String | Delivery address for the current cart. |
Type | Description |
---|---|
void |
Example
CartJS - setRequestedFor(String user)
Sets the sys_id in the sys_user record of the user for whom the cart is requested.
Name | Type | Description |
---|---|---|
user | String | sys_id to be set in the sys_user record of the user for whom the cart is requested. |
Type | Description |
---|---|
void |
Example
CartJS - setSpecialInstructions(String specialInstructions)
Sets the special instructions for the current cart.
Name | Type | Description |
---|---|---|
specialInstructions | String | Special instructions for the current cart. |
Type | Description |
---|---|
void |
Example
CartJS - submitOrder(Map request)
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.
Type | Description |
---|---|
JSON | Structure of the cart. |
Example
The following code example shows how to call this method.
Output:
CartJS - updateItem(Map request, String cart_item_id)
Updates an item in the cart.
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:
|
cart_item_id | String | sys_id of the cart item to be modified. |
Type | Description |
---|---|
JSON | Details of the cart. |
Example
Output
On this page
- CartJS - CartJS(String cartName)
- CartJS - addToCart(Map request)
- CartJS - canViewRF()
- CartJS - checkoutCart()
- CartJS - empty()
- CartJS - getCartDetails()
- CartJS - getCartID()
- CartJS - getCartItems()
- CartJS - getDeliveryAddress()
- CartJS - getRequestedFor()
- CartJS - getRequestedForDisplayName()
- CartJS - getSpecialInstructions()
- CartJS - orderNow(Map request)
- CartJS - setDeliveryAddress(String address)
- CartJS - setRequestedFor(String user)
- CartJS - setSpecialInstructions(String specialInstructions)
- CartJS - submitOrder(Map request)
- CartJS - updateItem(Map request, String cart_item_id)