Luis
08/27/2024, 8:36 PMCeligo AI
08/27/2024, 8:37 PMAI generated answer (using internal Slack threads):Under the hood, when you go to the "accept payment" page, select a customer, check the apply checkbox in a journal in the apply>invoice tab and also a payment in the apply>credits tab, if they have the same amount, and save, NetSuite is essentially creating a link between the journal and the existing previous payment that you selected in the credits tab. This is not creating a new payment record, but rather applying the journal to the existing payment. To replicate this behavior in SuiteScript, you would use the
record.transform
method to mimic the effect of the "Accept Payment" button. This method transforms a record from one type to another, in this case from an invoice to a customer payment.
Here is a sample code snippet that demonstrates this:
javascript
var paymentRecord = record.transform({
fromType: record.Type.INVOICE,
fromId: invoiceId,
toType: record.Type.CUSTOMER_PAYMENT,
isDynamic: true,
});
// Loop through the apply and credit sublists to select records
for (var i = 0; i < paymentRecord.getLineCount({sublistId: 'apply'}); i++) {
paymentRecord.selectLine({sublistId: 'apply', line: i});
paymentRecord.setCurrentSublistValue({sublistId: 'apply', fieldId: 'apply', value: true});
paymentRecord.commitLine({sublistId: 'apply'});
}
for (var i = 0; i < paymentRecord.getLineCount({sublistId: 'credit'}); i++) {
paymentRecord.selectLine({sublistId: 'credit', line: i});
paymentRecord.setCurrentSublistValue({sublistId: 'credit', fieldId: 'apply', value: true});
paymentRecord.commitLine({sublistId: 'credit'});
}
paymentRecord.save();
This script transforms an invoice to a customer payment, then loops through the 'apply' and 'credit' sublists of the payment record, marking each line as applied. Finally, it saves the payment record.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
08/27/2024, 8:37 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.864184856
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.854555249
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.853896
Celigo AI
08/27/2024, 8:37 PM