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);