This article is relevant if you need to programmatically or automatically apply open NetSuite credit memos to invoices.
Background
In many of our client implementation or new support situations, we are asked to help clean up concerns related to poor processing before we work with them to straighten out their recordkeeping practices. Other times, we are asked to create interesting innovations. Recently, we were asked to produce a mechanism where we could import both invoices and credit memos from a single CSV file. This can’t be done natively. But we have a free tool called the “Prolecto Record Import / Export Manager” designed to extend the challenges and limitations of NetSuite’s native CSV uploads. This tool allows us to use some SuiteScript to gain full control over the shape of the import.
Applying credit memos to invoices can be more challenging when doing it via SuiteScript because it is not obvious what to do.
SuiteScript 2.0 Function to Apply NetSuite Credit Memos to Invoices
Below is a NetSuite JavaScript function to help you. The key is to go through a payment record via a transform.
//pass the invoice internal ID we are trying to apply the credit which //can be sourced from mass update, scheduled workflow, map reduce pattern function applyCreditMemos(intInvoiceId){ // apply open credit memo(s) to invoice [assumption under the same AR account] var objCustPaymtRec = record.transform({ fromType : record.Type.INVOICE, fromId : intInvoiceId, toType : record.Type.CUSTOMER_PAYMENT, isDynamic : true }); if (objCustPaymtRec) { objCustPaymtRec.setValue('memo', 'Created to apply open credit memo(s)'); //assumption is that we will apply all the credit memo available var intAppliedLns = 0; var intCreditLns = objCustPaymtRec.getLineCount('credit'); for (var i = 0; i < intCreditLns; i++) { objCustPaymtRec.selectLine('credit', i); objCustPaymtRec.setCurrentSublistValue('credit', 'apply', true); objCustPaymtRec.commitLine('credit'); intAppliedLns++; } //only commit the payment record if we have indeed found credit memos if (intAppliedLns) { var intCustPaymtId = objCustPaymtRec.save({ enableSourcing : true, ignoreMandatoryFields : true }); log.debug(logTitle, '[2] Apply the Credit Memo(s): ' + intCustPaymtId); return intCustPaymtId; } } //if we get here, we didn't do work return null; }
Work with NetSuite Specialists
My hope is this article makes you more productive. Likely, you are a NetSuite Administrator or Developer who appreciates the power of NetSuite platform. If you would like to get closer to the Prolecto Team, let's have a conversation.
This is not working if I am setting the credit amount via script.
Hi,
I am trying to set the credit memo amount also after checking the apply checkbox to true. But after the payment record gets created the credit memos are not getting applied. Can you please help with this issue
Can you post your code so I can have a look?
Marty
Please see this article about the sequence for how to apply funds. It likely is relevant in this SuiteScript situation:
https://blog.prolecto.com/2024/09/14/when-sequence-matters-automating-complex-netsuite-cash-receipt-processes/
Marty