My problem is the last item from PO is always overwrite the first added item. Here my snipped code. thank you in advance
User Event
function beforeLoad(context) {
// try {
if (context.type == context.UserEventType.VIEW) {
var objPORec = context.newRecord;
var parentPOId = objPORec.id;
var form = context.form;
//Add Client Script File
form.clientScriptModulePath = './po_bill_btn.js'
form.addButton({
id: 'custpage_create_child_so',
label: 'Create Vendor Bill',
functionName: 'vendorBillFunc("' + parentPOId + '")'
});
}
}
clientscript
function init(context) {
currentRecord = context.currentRecord;
var items = [{ "item_display": "3247", "quantity": 1 }, { "item_display": "3247", "quantity": 1 }];
for (var x = 0; x < items.length; x++) {
addVendorBillLine(items, x);
}
}
function addVendorBillLine(itemList, x) {
currentRecord.selectNewLine({
sublistId: 'item'
});
currentRecord.setCurrentSublistText({
sublistId: 'item',
fieldId: 'item',
text: itemList[x].item_display
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: itemList[x].quantity
});
index = currentRecord.getCurrentSublistIndex({
sublistId: 'item'
})
console.log('index: ', index);
console.log('x: ', x);
currentRecord.commitLine({
sublistId: 'item'
});
}
function vendorBillFunc(poId) {
try {
//Get New Vendor Bill URL
var newBillUrl = 'https://netsuite.com/app/accounting/transactions/vendbill.nl?'; //Custom function to get new standard Vendor Bill URL
//Set Final URL for new Vendor Bill record
var finalUrl = newBillUrl + '&parentpoid=' + poId;
//Open Vendor Bill in new Tab
window.open(finalUrl, "_blank");
return true;
}
catch (ex) {
log.error("Error opening new Vendor Bill", ex.message);
return true;
}
}