Using Cart API() to add multiple cat items

mdash
Giga Guru

Hi,
Has anyone successfully added multiple items to a cart and placed order using Cart API()? I am having a hard time doing that.
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('my sys id');

for(var i=0;i<my Variable.length; i++){

cart.setVariable(item,'requested_for',requestedFor);
cart.setVariable(item,'requested_by',requestedBy);
cart.setVariable(item,'model',model);
cart.setVariable(item,'quantity',quantity);
cart.setVariable(item,'device_model_name',asset);
cart.update();
}
var rc = cart.placeOrder();
gs.log("Request is "+rc.number);

It only creates a one RITM attached to the REQ. Any clues?

Thanks

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Are you saying you want more than 1 RITM under same Request?

Are those RITMs belonging to same catalog item or different ones?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

They are same catalog items with different values for each iterations.

Hi,

As you have informed it will be having different values for variables although it is same catalog item; why not have it as separate request and RITM

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I am able to create multiple REQ-RITM pairs via script for each iteration. However the requirement is such that we need a single REQ with multiple RITMs.

The external integration supplies a JSON object with some models and their quantity. I want to create a single RITM for each element and place under a single REQ so that they can track it from their side.