ANS-1389 · ACCOUNTING & FINANCIAL CONFIGURATION
How to Optimize Customer Payment Application in NetSuite
Streamline the process of applying customer payments and credits by enabling quick transaction number entry directly on the payment record.
Short answer
To optimize customer payment application, create three custom free-form text fields on the Customer Payment record. Customize the payment form to place these fields under the "Apply" tab. Deploy a client-side SuiteScript 2.x script with a fieldChanged entry point to automatically find and apply transactions based on the entered numbers, significantly reducing manual effort.
Scenario
Users frequently encounter a time-consuming manual process when applying customer payments or credits in NetSuite, often requiring navigation through multiple pages to match transactions. This inefficiency leads to increased processing time and potential errors.
Solution
The solution involves creating custom fields, customizing the Customer Payment form, and implementing a client-side SuiteScript 2.x script to automate the application of payments and credits.
Create three new custom fields on the Customer Payment record:
- Transaction Number (Alert) with internal ID
custbody_tran_number_alert(Free-Form Text) - Transaction Number (Credit) with internal ID
custbody_tran_number_credit(Free-Form Text) - Transaction Number (Apply) with internal ID
custbody_tran_number_apply(Free-Form Text Ensure these fields have "Store Value" set toFalseas their values are only used for UI interaction.
- Transaction Number (Alert) with internal ID
Customize the Customer Payment forms:
Move the newly created custom fields to be visible under the "Apply" subtab on the relevant Customer Payment forms.
Create and deploy a client-side SuiteScript 2.x script on the Customer Payment record:
The script will trigger on field changes to automatically find and apply transactions based on the numbers entered into the custom fields.
javascript/** * @NApiVersion 2.x * @NScriptType ClientScript * @NModuleScope SameAccount */define(['N/record'], function(record) { /** * Function to be executed when field is changed. * * @param {object} scriptContext * @param {record.Record} scriptContext.currentRecord - Current form record * @param {string} scriptContext.sublistId - Sublist name * @param {string} scriptContext.fieldId - Field name * @param {number} scriptContext.lineNum - Line number in sublist * @param {number} scriptContext.columnNum - Column number in matrix sublist * * @since 2015.2 */ function fieldChanged(scriptContext) { var currentRecord = scriptContext.currentRecord; var fieldId = scriptContext.fieldId; if (fieldId === 'custbody_tran_number_apply') { findAndApply(currentRecord, fieldId, 'apply', 'custbody_tran_number_alert'); currentRecord.setValue({fieldId: fieldId, value: '', ignoreFieldChange: true}); } if (fieldId === 'custbody_tran_number_credit') { findAndApply(currentRecord, fieldId, 'credit', 'custbody_tran_number_alert'); currentRecord.setValue({fieldId: fieldId, value: '', ignoreFieldChange: true}); } } /** * findAndApply : Gets the transaction number value given the * transaction number field name, * iterates through a given sublist (sublist name), finds the related * transaction, applies and * sets the amount to the amount due. * * When the transaction number cannot be found an alert message is displayed. * * This is done to optimize apply/credit matching (no need to switch * pages and go through the * lengthy manual process; you can just input the numbers in the two * text fields) * * @param {record.Record} currentRecord : The current record object. * @param {string} transactionNumberFieldName : transaction number field id * @param {string} sublistName : sublist id ('apply' or 'credit') * @param {string} alertFieldName : alert field id * * @author frederic.jannelle@erpguru.com */ function findAndApply(currentRecord, transactionNumberFieldName, sublistName, alertFieldName) { var transactionNumberToApply = currentRecord.getValue({fieldId: transactionNumberFieldName}); if (transactionNumberToApply !== null && transactionNumberToApply !== '') { var numberOfLines = currentRecord.getLineCount({sublistId: sublistName}); var lineFound = false; for (var i = 0; i < numberOfLines && !lineFound; i++) { var refNumber = currentRecord.getSublistValue({sublistId: sublistName, fieldId: 'refnum', line: i}); if (refNumber === transactionNumberToApply) { var amountDue = currentRecord.getSublistValue({sublistId: sublistName, fieldId: 'due', line: i}); // Need to select line and commit, otherwise the application // is not triggered in the UI (ie: payment amount, // applied, unapplied are not updated) currentRecord.selectLine({sublistId: sublistName, line: i}); currentRecord.setCurrentSublistValue({sublistId: sublistName, fieldId: 'apply', value: true}); currentRecord.setCurrentSublistValue({sublistId: sublistName, fieldId: 'amount', value: amountDue}); currentRecord.commitLine({sublistId: sublistName}); currentRecord.setValue({fieldId: alertFieldName, value: '', ignoreFieldChange: true}); lineFound = true; } } if (!lineFound) { currentRecord.setValue({fieldId: alertFieldName, value: transactionNumberToApply + ' not found.', ignoreFieldChange: true}); } } } return { fieldChanged: fieldChanged };});The script defines a fieldChanged entry point that monitors the custom transaction number fields. When a number is entered, the findAndApply function is called. This function iterates through the relevant sublist (either 'apply' for payments or 'credit' for credits), searches for a matching transaction reference number, and then automatically selects the line, sets the 'Apply' checkbox to true, and populates the 'Amount' field with the 'Amount Due'. If the transaction is not found, an alert message is displayed in the custbody_tran_number_alert field.
Expert NetSuite Support
Need help with this NetSuite issue?
Accounting & Financial Configuration consulting and configuration support
