acuestajohnmark
04/21/2026, 1:33 PMAnthony OConnor
04/21/2026, 2:34 PMAnthony OConnor
04/21/2026, 2:40 PMconst payment = record.transform({
fromType: record.Type.INVOICE,
fromId: invoiceId,
toType: record.Type.CUSTOMER_PAYMENT,
isDynamic: true
});
// Find and update the apply line for our invoice
const applyCount = payment.getLineCount({ sublistId: 'apply' });
for (let i = 0; i < applyCount; i++) {
const doc = payment.getSublistValue({
sublistId: 'apply',
fieldId: 'doc',
line: i
});
if (doc === invoiceId) {
payment.selectLine({
sublistId: 'apply',
line: i
});
payment.setCurrentSublistValue({
sublistId: 'apply',
fieldId: 'apply',
value: true
});
payment.setCurrentSublistValue({
sublistId: 'apply',
fieldId: 'amount',
value: creditAmount
});
payment.commitLine({
sublistId: 'apply'
});
break;
}
}
// Find and update credit line for the journal entry
const creditCount = payment.getLineCount({ sublistId: 'credit' });
for (let i = 0; i < creditCount; i++) {
const doc = payment.getSublistValue({
sublistId: 'credit',
fieldId: 'doc',
line: i
});
if (doc === journalId.toString()) {
payment.selectLine({
sublistId: 'credit',
line: i
});
payment.setCurrentSublistValue({
sublistId: 'credit',
fieldId: 'apply',
value: true
});
payment.setCurrentSublistValue({
sublistId: 'credit',
fieldId: 'amount',
value: creditAmount
});
payment.commitLine({
sublistId: 'credit'
});
break;
}
}
// this is a NetSuite magic trick: calling .save() on a payment
// record where the attached invoice has a journal entry that
// cancels out the G/L impact will mark the Invoice as PAID
const paymentId = payment.save();
log.debug('Created customer payment', { paymentId });
return paymentId;
}Anthony OConnor
04/21/2026, 2:42 PMAnthony OConnor
04/21/2026, 2:42 PMacuestajohnmark
04/21/2026, 2:47 PMconst make_je_record = record.create({
type: 'journalentry',
isDynamic : true,
defaultValues: { subsidiary: chosenSubsidiary }
});
make_je_record.setValue({ fieldId: 'custbody_ct_240830_jetype', value: 5 }); // JOURNAL TYPE = OTHERS
make_je_record.setValue({ fieldId: 'currency', value: chosenCurrency });
make_je_record.setValue({ fieldId: 'approvalstatus', value: 2 }); // APPROVAL STATUS = APPROVED
make_je_record.setValue({ fieldId: 'custbody_ct_240830_crtd_fr_apar_offst', value: true });
make_je_record.selectNewLine({sublistId: "line"});
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "account", value: chosenArAccount });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "credit", value: parseFloatOrZero(currentArTotal) });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "entity", value: chosenCustomer} );
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "department", value: chosenDepartment });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "cseg_ct_240830_clss", value: chosenCostCenter });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "cseg_ful_site", value: chosenSite });
make_je_record.commitLine({sublistId: "line"});
make_je_record.selectNewLine({sublistId: "line"});
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "account", value: chosenApAccount });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "debit", value: parseFloatOrZero(currentApTotal) });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "entity", value: chosenVendor} );
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "department", value: chosenDepartment });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "cseg_ct_240830_clss", value: chosenCostCenter });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "cseg_ful_site", value: chosenSite });
make_je_record.commitLine({sublistId: "line"});
const created_je_id = make_je_record.save({ enableSourcing: true, ignoreMandatoryFields: true });
log.emergency('created_je_id', created_je_id);
const je_obj = {};
je_obj.transactionId = created_je_id;
je_obj.transactionType = 'journalentry';
je_obj.paidAmount = parseFloatOrZero(currentApTotal);
billsPaymentArray data:
[{"transactionId":"1696348","transactionType":"vendorbill","paidAmount":1.12}]
here's the snippet that transforms each vendor bill ticked on a custom UI.
billsPaymentArray.forEach((billPayment) => {
const make_billPayment_record = record.transform({
fromType: billPayment.transactionType,
fromId: billPayment.transactionId,
toType: record.Type.VENDOR_PAYMENT,
isDynamic: true
});
make_billPayment_record.setValue({ fieldId: 'apacct', value: chosenApAccount, ignoreFieldChange: false });
make_billPayment_record.setValue({ fieldId: 'currency', value: chosenCurrency, ignoreFieldChange: false });
const vendorBillLineNum = make_billPayment_record.findSublistLineWithValue({
sublistId: 'apply',
fieldId: 'internalid',
value: billPayment['transactionId']
});
make_billPayment_record.selectLine({
sublistId: 'apply',
line: vendorBillLineNum
});
make_billPayment_record.setCurrentSublistValue({
sublistId: 'apply',
fieldId: 'apply',
value: true,
ignoreFieldChange: false
});
make_billPayment_record.setCurrentSublistValue({
sublistId: 'apply',
fieldId: 'amount',
value: billPayment['paidAmount'],
ignoreFieldChange: false
});
make_billPayment_record.commitLine({
sublistId: 'apply'
});
const jeLineNum = make_billPayment_record.findSublistLineWithValue({
sublistId: 'apply',
fieldId: 'internalid',
value: je_obj['transactionId']
});
make_billPayment_record.selectLine({
sublistId: 'apply',
line: jeLineNum
});
make_billPayment_record.setCurrentSublistValue({
sublistId: 'apply',
fieldId: 'apply',
value: true,
ignoreFieldChange: false
});
make_billPayment_record.setCurrentSublistValue({
sublistId: 'apply',
fieldId: 'amount',
value: billPayment['paidAmount'] * -1,
ignoreFieldChange: false
});
make_billPayment_record.commitLine({
sublistId: 'apply'
});
log.emergency({
title: 'setup',
details: {
vendorBillLineNum,
// jeLineNum,
billPayment
}
});
log.emergency({
title: 'getvalues',
details: {
vbApply: make_billPayment_record.getSublistValue({
sublistId: 'apply',
fieldId: 'apply',
line: vendorBillLineNum
}),
jeApply: make_billPayment_record.getSublistValue({
sublistId: 'apply',
fieldId: 'apply',
line: jeLineNum
}),
vbAmount: make_billPayment_record.getSublistValue({
sublistId: 'apply',
fieldId: 'amount',
line: vendorBillLineNum
}),
jeAmount: make_billPayment_record.getSublistValue({
sublistId: 'apply',
fieldId: 'amount',
line: jeLineNum
}),
entity: make_billPayment_record.getValue({
fieldId: 'entity'
}),
subsidiary: make_billPayment_record.getValue({
fieldId: 'subsidiary'
}),
apacct: make_billPayment_record.getValue({
fieldId: 'apacct'
}),
currency: make_billPayment_record.getValue({
fieldId: 'currency'
})
}
});
const created_bp_id = make_billPayment_record.save({ ignoreMandatoryFields: true });
log.emergency('POST_created_bp_id', created_bp_id);
});acuestajohnmark
04/21/2026, 2:49 PMAnthony OConnor
04/21/2026, 3:00 PM0?acuestajohnmark
04/21/2026, 3:02 PMcreated_bp_id just gives 0Anthony OConnor
04/21/2026, 3:07 PMAnthony OConnor
04/21/2026, 3:08 PMAnthony OConnor
04/21/2026, 3:09 PMchosenApAccount the same account on the JE lines? and is that a valid account for a vendor payment for that entity/sub combination?acuestajohnmark
04/21/2026, 3:10 PMAnthony OConnor
04/21/2026, 3:11 PMmake_billPayment_record.setCurrentSublistValue({
sublistId: 'apply',
fieldId: 'amount',
value: (billPayment['paidAmount'] * -1)+0.01,
ignoreFieldChange: false
});acuestajohnmark
04/21/2026, 3:11 PMAnthony OConnor
04/21/2026, 3:11 PMAnthony OConnor
04/21/2026, 3:12 PMAnthony OConnor
04/21/2026, 3:12 PMAnthony OConnor
04/21/2026, 3:14 PMacuestajohnmark
04/21/2026, 3:18 PMacuestajohnmark
04/21/2026, 3:21 PMAnthony OConnor
04/21/2026, 3:36 PMAnthony OConnor
04/21/2026, 3:48 PMAnthony OConnor
04/21/2026, 3:49 PMacuestajohnmark
04/21/2026, 3:55 PMacuestajohnmark
04/21/2026, 3:55 PMAnthony OConnor
04/21/2026, 4:07 PMacuestajohnmark
04/22/2026, 9:05 AMacuestajohnmark
04/22/2026, 9:08 AMacuestajohnmark
04/22/2026, 9:08 AMAnthony OConnor
04/22/2026, 12:46 PMAnthony OConnor
04/22/2026, 12:46 PMAnthony OConnor
04/22/2026, 12:48 PMAnthony OConnor
04/22/2026, 12:52 PMacuestajohnmark
04/22/2026, 1:01 PMacuestajohnmark
04/22/2026, 1:02 PMAnthony OConnor
04/22/2026, 1:06 PMAnthony OConnor
04/22/2026, 1:07 PMacuestajohnmark
04/22/2026, 1:08 PMAnthony OConnor
04/22/2026, 1:08 PMAnthony OConnor
04/22/2026, 1:09 PMAnthony OConnor
04/22/2026, 1:09 PMAnthony OConnor
04/22/2026, 1:10 PM