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 06:52 AM
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
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:56 AM
Hi Ankur,
They are same catalog items with different values for each iterations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 07:02 AM
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
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 07:16 AM
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.