Using Cart API() to add multiple cat items
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 06:49 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 08:27 AM
Hi,
are you saying you want 1 REQ0001 with more than 1 RITM under it; all RITMs belonging to same catalog item?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 11:13 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 10:04 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2020 10:05 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 06:54 AM
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!