Thank you for your feedback.
Form temporarily unavailable. Please try again or contact docfeedback@servicenow.com to submit your comments.
Versions
  • London
  • Kingston
  • Jakarta
  • Istanbul
  • Helsinki
  • Geneva
  • Store
Close

Service catalog script API

Service catalog script API

A scriptable API for the service catalog makes it easier to order from the catalog when using business rules.

The Cart() API allows you to order any quantity of catalog items, using the sys_id of the Catalog Item [sc_cat_item] you want. You can then set catalog variables to values as required, assuming the variables have names.

Note: If the script runs as a result of a scheduled import, the script runs as system or as the user specified by that import in the Run as field. The script uses the specified user’s cart. Each instantiation of a new Cart() object empties the cart of the calling user, but does not use or empty any other carts.

Examples

Ordering a single BlackBerry:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e2132865c0a8016500108d9cee411699');
var rc = cart.placeOrder(); 
gs.addInfoMessage(rc.number);

Ordering twelve BlackBerries:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e2132865c0a8016500108d9cee411699',12);
var rc = cart.placeOrder(); 
gs.addInfoMessage(rc.number);

Ordering an executive desktop and setting its OS:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f'); 
cart.setVariable(item,'os','Linux Red Hat');
var rc = cart.placeOrder(); 
gs.addInfoMessage(rc.number);

This site is scheduled for a small content update on Tuesday, December 18th, between the hours of 4:00pm and 8:00pm Pacific Time (Dec 19 00:00 – Dec 19 4:00 UTC). Access to this site may be slightly delayed during that time.