Add items to cart through script

brostoff17
Tera Contributor

I am trying to have a script add additional items to a cart when a user clicks "proceed to checkout" automatically.   I have tried to write a client script, but get the alert the glide system cant be used.   Any ideas how I could add a catalog item to a cart automatically through a script when someone proceeds to a checkout?

This is what I currently have which is not working:

function onSubmit() {

var existingCart = new GlideRecord('sc_cart');

existingCart.addQuery('user', gs.getUserID());

existingCart.query();

if(existingCart.next()){

      var cart = new Cart(); // using "new Cart()" object without parameters

      cart.getCart(existingCart.sys_id);   // here is where you grab the existing cart. this is not the "getCart()" function from the wiki

      var item = cart.addItem('e212a942c0a80165008313c59764eea1');

}

}

3 REPLIES 3

Deepak Ingale1
Mega Sage

Hi Josh,



We can not use server side API directly in client script,



in order to do that, we need to write down client callable script include



http://wiki.servicenow.com/index.php?title=GlideAjax#Overview


Deepak - is there an easier way of achieving what I am trying to do?


pradeepksharma any ideas?