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.
New AI Community Guidelines. Please review and follow them to ensure AI use stays safe, accurate, and compliant.
Update: Narrative Insights has been restored and is now available.
Narrative Insights is Temporarily Unavailable due to an Infrastructure Issue. Learn how This Impacts Your Account and What to Expect While the Feature is Disabled.
Narrative Insights is Temporarily Unavailable due to an Infrastructure Issue. Learn how This Impacts Your Account and What to Expect While the Feature is Disabled.
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