Learn about the intricacies of the customer payment record

Introduction

The customer payment record is used to record a payment from a customer in NetSuite.  You basically select the customer, payment method, and payment amount.  You can optionally select invoices to apply the payment to.

You can also use this record to directly pay invoices using open customer deposits or credit memos.   What some people don’t know is that you can do this without creating a customer payment.  When the amounts line up correctly no customer payment record will be created but the invoices will be paid and the customer deposits or credit memos applied.  Let me walk you through a simple example.

I created this invoice for $135.34.

 

I then created this customer deposit for the same customer for $135.34.

 

Now if you go back to the invoice and click “Accept payment” you will see that the payment record shows a payment amount for $135.34, and the invoice is selected on the “Invoices” tab.

 

 

But what about the open deposit that we just created?  If you click on the deposits tab you will see the deposit and it is not applied.  Check the apply box and you will see that the payment amount goes to zero.  You also see the invoice amount and the deposit amount are equal.

 

Now click save and you will see this page below.  No customer payment record was created as the deposit was applied to the invoice.

 

Go back to the invoice record and go to the related records tab.  You see that a Deposit Application record was created which has applied the customer deposit to the invoice.

 

I’ve seen multiple NetSuite accounts where there are old open invoices which have not been paid.  This can happen for a variety of reasons.  This is where I am tasked with writing a script to clean up the unpaid invoices.

Let’s write a map/reduce script which takes a list of customers and applies all the open deposits to the open invoices.  We will assume that the deposit and invoice amount match.  We don’t want to create any new customer payment records.  If one is created, we will delete it immediately and log an error.

Add and deploy the script (code shown below).  Reference my article “Quick Guide to Adding and Deploying a Script in NetSuite” if needed.

 

/**
 * @NApiVersion 2.1
 * @NScriptType MapReduceScript
 * @NModuleScope SameAccount

*/

define([ 'N/runtime', 'N/record', 'N/search'],
(runtime, record, search) => {

    getInputData = (context) => {
        log.debug('==START==','==START==');
        let customers = [
            324
        ];
        return customers;
    }

    map = (context) => {
        try {
            let customerId = context.value;

            let paymentRecord = record.create({
                type: record.Type.CUSTOMER_PAYMENT,
                isDynamic: true
            });
            paymentRecord.setValue('customer', customerId);
            // apply invoices
            let lineCount = paymentRecord.getLineCount({sublistId: 'apply'});
            for (let i = 0; i < lineCount; i++) {
                let currentLine = paymentRecord.selectLine({sublistId: 'apply',line: i});
                paymentRecord.setCurrentSublistValue({sublistId: 'apply',fieldId: 'apply',value: true});
                paymentRecord.commitLine({sublistId: 'apply'});
            }
            // apply deposits
            let lineCount = paymentRecord.getLineCount({sublistId: 'deposit'});
            for (let i = 0; i < lineCount; i++) {
                let currentLine = paymentRecord.selectLine({sublistId: 'deposit',line: i});
                paymentRecord.setCurrentSublistValue({sublistId: 'deposit',fieldId: 'apply',value: true});
                paymentRecord.commitLine({sublistId: 'deposit'});
            }

            let paymentId = paymentRecord.save();
            if (paymentId) {
                // payment created in error, delete and show error
                record.delete({
                    type: record.Type.CUSTOMER_PAYMENT,
                    id: paymentId
                });
                log.error('ERROR', 'Incorrectly created a customer payment record for customer' + customerId);
            }
            else {
                log.debug('Success','Successfully applied payments to invoices for customer ' + customerId);
            }
        }
        catch(e) {
            log.error('Error', JSON.stringify(e));
        }
    }

    summarize = (summary) => {
        log.debug('==END==','==END==');
    }

    return {
        getInputData: getInputData,
        map: map,
        summarize: summarize
    };

});

 

You can test this script by creating an invoice and deposit as we did earlier in this article.  You then just need to update the customer ID in the getInputData() function.  After running the script you should see the invoice paid using the customer deposit and the deposit application has been created.

Do you need help cleaning up open transactions in NetSuite? Please contact Suite Tooth consulting here to set up a free consultation.

If you liked this article, please sign up for my newsletter to get these delivered to your inbox here.

Follow on
Jaime Requena Chief Executive Officer

Jaime Requena is a seasoned NetSuite Consultant and Solutions Architect, known for delivering WHITE GLOVE service to businesses. With 15+ years of experience and 3x certifications in ERP, Developer, and Admin, Jaime specializes in highly customized NetSuite accounts, transforming operations for 200+ satisfied customers all across the globe.

Get Connected

How can we help?


    Stay in the loop with Suite Tooth Consulting!

    We aim to bring unmatched expertise and professionalism to your NetSuite initiatives. Let’s talk about how our NetSuite consultancy can make a difference!

    Global Client Satisfaction

    Client Testimonials

    It’s Been 4+ Years Now And We Have Worked With Hundreds Of Clients, Building Our Way To The Top, One Happy Client After Another! Their Voices Of Satisfaction Serve As A Testament To Our Success –