Discussions
Stay up-to-date with the latest news from NetSuite. You’ll be in the know about how to connect with peers and take your business to new heights at our virtual, in-person, on demand events, and much more.
Now is the time to ask your NetSuite-savvy friends and colleagues to join the NetSuite Support Community! Refer now! Click here to watch and learn more!
Update your Profile with your Support type to get your Support Type badge.
Expand your NetSuite knowledge by joining our Ask A Guru Live sessions. RSVP on this event now.
Uncover the power of data with the Analytics Hub —your ultimate guide to mastering NetSuite Saved Searches and Reports. Simplify the complex and unlock your organization's true potential. Dive into the Analytics Hub now and soar to new heights!
To help you get the most out of your 2025.2 Release Preview account, review the topics outlined in the 2025.2 Release Preview Guide.
Share Your SuiteWorld Experience & Earn a Special Badge!
SSP: Adding Items Error
I am creating a .ss function that will add an item to an order if it isn't currently in the order. When the script gets ran, I get the following error message.
"Failed when adding item to cart"
The item exists and can be added from the website fine. I also used the singular version of addItems(order.addItem(item)), but received the same error. Any help would be appreciated.
function service(request,response) { var shoppingCartItemId = "22"; var order = nlapiGetWebContainer().getShoppingSession().getOrder(); var items = order.getFieldValues({ 'items': ['internalid'] }); var hasShoppingCartItem = false; if (items.items != null) { for (i = 0; i < items.items.length; i++) { if (items.items[i].internalid == shoppingCartItemId) { hasShoppingCartItem = true; } } } var itemArray = new Array(); if (!hasShoppingCartItem) { var item = { internalid : shoppingCartItemId, quantity : 1 }; itemArray.push(item); order.addItems(itemArray); } var itemsJSON = JSON.stringify(order.getFieldValues({ 'items': ['name', 'salesdesc', 'quantity', 'rate', 'amount', 'options'], 'summary': ['total'] })); try { response.setContentType('JSON'); response.writeLine(itemsJSON); } catch (exception) { var e2 = nlapiCreateError(e); } }
0