Netsuite Tragic
11/06/2023, 11:05 AMif (context.type !== context.UserEventType.CREATE && context.type !== context.UserEventType.EDIT) {
return; // Only run on creation or editing of Vendor Payment record
}
var newRecord = context.newRecord;
var vendorPaymentMemo = '';
var paidBills = [];
// Get the paid vendor bills linked to this vendor payment
var lineCount = newRecord.getLineCount({ sublistId: 'apply' });
for (var i = 0; i < lineCount; i++) {
if (newRecord.getSublistValue({ sublistId: 'apply', fieldId: 'apply', line: i })) {
var paidBill = newRecord.getSublistValue({ sublistId: 'apply', fieldId: 'doc', line: i });
if (paidBill && paidBills.indexOf(paidBill) === -1) {
paidBills.push(paidBill);
}
}
}
// If paid bills were found, construct the vendor payment memo
if (paidBills.length > 0) {
var billSearch = search.create({
type: search.Type.VENDOR_BILL,
filters: [['internalid', 'anyof', paidBills],'AND',
['mainline', 'is', 'T']],
columns: ['tranid']
});
var results = billSearch.run().getRange({ start: 0, end: 1000 }); // Limit to 1000 bills
for (var i = 0; i < results.length; i++) {
vendorPaymentMemo += results[i].getValue({ name: 'tranid' }) + ', ';
}
vendorPaymentMemo = vendorPaymentMemo.slice(0, -2) // Remove the final ', '
// Set the vendor payment memo
newRecord.setValue({ fieldId: 'memo', value: vendorPaymentMemo });
Netsuite Tragic
11/07/2023, 8:01 AMNetsuite Tragic
11/07/2023, 8:01 AMDavid B
11/07/2023, 7:55 PM