ItemOption.ss

/* http://www.mystore.com/test/itemOption.ss */ function service(request,response) { try { var thesize = request.getParameter('size'); var msg = request.getParameter('msg'); if (thesize == null || msg == null) { throw "Parameters 'size' and 'msg' need to be included"; } var order = nlapiGetWebContainer().getShoppingSession().getOrder(); var itemid = '74'; var qty = '8'; var optionMap = { 'custcol_size':'2', 'custcol_message':'FIRST MESSAGE' }; var itemMap = {'internalid' : itemid, 'quantity': qty, 'options' : optionMap }; order.addItem(itemMap); response.writeLine("Finished adding new item"); writeOrder(order); var itemArray = order.getFieldValues(['items']).items; response.writeLine("Number of order lines "+itemArray.length); // Get the order item ID from the order var theitemid = itemArray[0].orderitemid; response.writeLine("The order item ID is "+theitemid); // Now update the item options var thesize = request.getParameter('size'); var msg = request.getParameter('msg'); optionMap = { 'custcol_size' : thesize, 'custcol_message':msg}; order.setItemOptions(theitemid, optionMap); response.writeLine("Updated item option"); writeOrder(order); /* response.writeLine("Clearing the cart"); order.removeAllItems(); */ } catch (ex) { response.writeLine(ex); } } function writeOrder(order) { var orderDetails = order.getFieldValues(['items']); var orderItems = new Array(); for (var i = 0; i < orderDetails.items.length; i++) { var orderItem = {}; orderItem.internalid = orderDetails.items[i].internalid; orderItem.orderitemid = orderDetails.items[i].orderitemid; orderItem.quantity = orderDetails.items[i].quantity; orderItem.rate = orderDetails.items[i].rate; orderItem.amount = orderDetails.items[i].amount; orderItem.name = orderDetails.items[i].name; orderItem.options = orderDetails.items[i].options; orderItems[i] = orderItem; } response.writeLine(JSON.stringify(orderItems)); }