This article demonstrates adding a line item to an order in NetSuite with JavaScript. Start by clicking the hook icon () on an import in Flow Builder.
The following JavaScript function checks for empty data returned from an import step within a flow. Add the script to your account, and then apply this function to an import hook.
function addDiscountLineItem(options) { return options.data.map((d) => { // for each order var errorsArray = []; var errorMessage = ''; const error = {}; if(d === null || d.length === 0) { errorMessage = 'd is NULL or EMPTY'; error = {code:"ERROR", message: errorMessage, source:'addDiscountLineItem'}; errorsArray.push(error); console.log(error); } var items = d.order.items || []; var lineItem; var discountAmount = 0; var diff = 0; try { for(var i=0; i < items.length; i++) { // for each item in order lineItem = items[i]; diff = parseFloat(lineItem.gross) - parseFloat(lineItem.base); if (diff != 0) { discountAmount += diff; } } if (discountAmount != 0) { var discountLineItem = { "number": "0", "quantity": "1", "gross": discountAmount, "base": discountAmount }; items.push(discountLineItem); d.order.items = items; } } catch(err) { errorsArray.push(err); } return { data: d } }) }
Comments
Hi,
I wanted to add a hook but the flow from celigo "Magento Order to NetSuite Order Add" is locked and wont let you add a javascript except the ones originally added by celigo.
How to go about using a hook with the flow?
Hi Zaid Ghansar :) how are you?
The flow in question is locked by design, as it's a prebuilt flow.
If you want to make such modifications to a flow, the best option is to consider building your own flow. You could even start from a template flow (see this marketplace template) to get things going.
That said, what's the use-case you're working on? What's the challenge you're trying to solve?
Kind Regards,
Adel
I need to bring in our store credit (which is a discount on the magneto order) into netsuite as line item with negative values in addition to the current coupon code which is already brought in as a discount item.
Issue is "discount item" is already in use in the template mapping so it wont let me add another "discount item" and "rate" says duplicate. If i can achieve that it will spare me from javascript
Hi Zaid Ghansar
Here's how I would consider doing that:
Kind Regards,
Adel
Please sign in to leave a comment.