I am trying to add discount using custom column, I...
# general
j
I am trying to add discount using custom column, I found a solution in suiteanswer but seems like something is missing on my script below: function userEventAfterSubmit(type){ recType = nlapiGetRecordType(); recID = nlapiGetRecordId(); var recLoad = nlapiLoadRecord(recType, recID); var itemcnt = recLoad.getLineItemCount('item'); var itemdiscnt = recLoad.getLineItemCount('item'); var linenumber; for (var i = 1; i <= itemcnt;i++) { var itemType = recLoad.getLineItemValue('item', 'itemtype', i); var itemId = recLoad.getLineItemValue('item', 'item', i); if (itemType == 'InvtPart') { linenumber = i; for (var j = i; j <= itemcnt; j++) { itemId = recLoad.getLineItemValue('item', 'item', j); itemType = recLoad.getLineItemValue('item', 'itemtype', j); if(itemType!='InvtPart') { if (itemId == '672') { //Internal ID of the Discount Item var dct = recLoad.getLineItemValue('item', 'rate', j); recLoad.setLineItemValue('item', 'custcol_row_discount', linenumber, dct); i++; } } else if(itemType=='InvtPart' && i!=linenumber){ i++; break; }//end if inventory part } // end of second loop }//first if }//first for loop var id = nlapiSubmitRecord(recLoad, true); } // end function function isNullOrEmpty(val) { return (val == null || val == '' || val == undefined); }
r
this may also help in future
function isEmpty(arg){ if(arg === null){ return true;} if(arg === undefined){return true;} if(typeof arg === 'number'){ return isNaN(arg);} if(typeof arg === 'string'){ return arg.length === 0;} if(arg.isArray !== undefined){ return arg.length === 0;} if(typeof arg === 'object'){ for(var key in arg){if(!isEmpty(arg[key])){return false;}} return true; } }
Lastly, you need to nlapicommitLineItem(type) to commit the sub list item you added, even if it's a custom column https://system.netsuite.com/app/help/helpcenter.nl?fid=section_N3042487.html#bridgehead_N3043223
j
Hi Ryan, thanks, I was able to use a simple client script