NetSuite gives us a native way to do this using the Custom GL Lines Plug-in. The Custom GL Lines Plug-in allows you to modify the GL impact of standard and custom transactions. It does this by adding custom GL lines to the GL impact. I will detail a customization to reclass GL using a custom record to drive the reclassing.
The custom record will have three fields:
Your custom record should look like this:
For the example below, this record will reclass account 1100 Accounts Receivable: Accounts Receivable – Customers to account 1600 Accumulated Depreciation. It will only do this on the Invoice and Sales Order records.
/* Use a custom record to drive creation of Custom GL lines */
function customizeGlImpact(transactionRecord, standardLines, customLines, book) {
try {
var tranType = transactionRecord.getRecordType();
nlapiLogExecution('DEBUG', 'Transaction Type', tranType);
var tranTypeId = transactionRecord.getFieldValue('ntype');
nlapiLogExecution('DEBUG', 'Transaction Type Id', tranTypeId);
var customGlDataArray = getCustomGLRecords(tranTypeId);
nlapiLogExecution('DEBUG', 'Custom Records Available', customGlDataArray.length);
var amountsForAccounts = getAmountsForAccounts(standardLines);
for (var i = 0; i < customGlDataArray.length; i++) {
var customGLData = customGlDataArray[i];
if (customGLData.to && customGLData.from) {
var amountForAccount = amountsForAccounts[customGLData.from];
nlapiLogExecution("DEBUG", "Amount for account : ", amountForAccount);
if (amountForAccount != 0) {
var newLine1 = customLines.addNewLine();
newLine1.setAccountId(parseInt(customGLData.from));
newLine1.setMemo("Custom Line 1");
if (amountForAccount < 0) {
newLine1.setDebitAmount(Math.abs(amountForAccount));
}
else {
newLine1.setCreditAmount(amountForAccount);
}
var newLine2 = customLines.addNewLine();
newLine2.setAccountId(parseInt(customGLData.to));
newLine2.setMemo("Custom Line 2");
if (amountForAccount < 0) {
newLine2.setCreditAmount(Math.abs(amountForAccount));
}
else {
newLine2.setDebitAmount(amountForAccount);
}
}
}
}
}
catch (ex) {
nlapiLogExecution('DEBUG', 'Error', JSON.stringify(ex));
}
}
/* Get the custom record GL Reclass data for this record type */
function getCustomGLRecords(tranTypeId) {
var customGlDataArray = [];
var reclassSearch = nlapiSearchRecord("customrecord_custom_gl_reclass", null,
[
["custrecord_record_type", "anyof", tranTypeId]
],
[
new nlobjSearchColumn("name"),
new nlobjSearchColumn("custrecord_record_type"),
new nlobjSearchColumn("custrecord_account_from"),
new nlobjSearchColumn("custrecord_account_to")
]
) || [];
for (var i = 0; i < reclassSearch.length; i++) {
var data = {};
data.name = reclassSearch[i].getValue('name');
data.from = reclassSearch[i].getValue('custrecord_account_from');
data.to = reclassSearch[i].getValue('custrecord_account_to');
customGlDataArray.push(data);
}
return customGlDataArray;
}
/* Get the amounts for each account */
function getAmountsForAccounts(standardLines) {
var standardLineCount = standardLines.getCount();
var amountsForAccounts = {};
for (var i = 0; i < standardLineCount; i++) {
var selectedLine = standardLines.getLine(i);
var account = selectedLine.getAccountId();
if (!amountsForAccounts[account]) {
amountsForAccounts[account] = 0;
}
var debitAmount = selectedLine.getDebitAmount();
var creditAmount = selectedLine.getCreditAmount();
amountsForAccounts[account] += parseFloat(debitAmount) + (parseFloat(creditAmount) * parseFloat(-1));
}
return amountsForAccounts;
}
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.
We aim to bring unmatched expertise and professionalism to your NetSuite initiatives. Let’s talk about how our NetSuite consultancy can make a difference!
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 –