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

Hi,

are you saying you want 1 REQ0001 with more than 1 RITM under it; all RITMs belonging to same catalog item?

Regards
Ankur

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

Hi Ankur,

Yes, based on the number of objects returned from the JSON, I want to be able to submit those many catalog item instances under a single request. 

All I want is some snippet/function name to insert one or more request item into a cart.

Hi,

Recently I have published a blog regarding this; please have a look on that

https://community.servicenow.com/community?id=community_blog&sys_id=3dfb35c5dbfb04945129a851ca961942

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi

Any update on this?
Can you mark my answer as correct, 👍 helpful if you were able to achieve the requirement. This enables other members to learn from this thread.

Regards
Ankur

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

Allen Andreas
Administrator
Administrator

Hi,

Please see if this assists you:

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/r_CJSS-CartJS

And another use here:

https://hi.service-now.com/kb_view.do?sysparm_article=KB0721274

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!