Milcho Dimkov
11/14/2024, 1:54 PMCeligo AI
11/14/2024, 1:54 PMAI generated answer (using internal Slack threads):To apply a credit memo to an invoice via SuiteScript, you do not necessarily need to create a customer payment. However, creating a customer payment is the standard approach to apply different transactions to the invoice, including credit memos, unapplied payments, and journal entries. You can use the
record.transformRecord.setSublistValuejavascript
var payment = record.transform({
    fromType: record.Type.INVOICE,
    fromId: invoiceId,
    toType: record.Type.CUSTOMER_PAYMENT,
    isDynamic: true,
});
var lineCount = payment.getLineCount({ sublistId: 'apply' });
for (var i = 0; i < lineCount; i++) {
    var apply = payment.getSublistValue({ sublistId: 'apply', fieldId: 'apply', line: i });
    if (apply) {
        payment.setSublistValue({ sublistId: 'apply', fieldId: 'apply', line: i, value: true });
    }
}
payment.save();Celigo AI
11/14/2024, 1:54 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.881737113
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847923577
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847051501
Celigo AI
11/14/2024, 1:54 PM