hi @Komal Kumar can you help on this ? why still posting the GL impact? i want replace the default GL impact, if my taxcode is equal to 4508
/**
* @NApiVersion 2.0
* @NScriptType CustomGLPlugin
*/
define(['N/log'], function (log) {
function customizeGlImpact(context) {
try {
log.debug("Running customizeGlImpact");
var transactionRecord = context.transactionRecord;
var customLines = context.customLines;
var standardLines = context.standardLines;
if (!customLines || !standardLines) {
log.error("Missing GL line references.");
return;
}
var itemCount = transactionRecord.getLineCount({ sublistId: 'item' });
for (var i = 0; i < itemCount; i++) {
var itemType = transactionRecord.getSublistValue({
sublistId: 'item',
fieldId: 'itemtype',
line: i
});
if (itemType === 'InvtPart') {
var taxCode = transactionRecord.getSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
line: i
});
if (taxCode === '4508') {
var amount = transactionRecord.getSublistValue({
sublistId: 'item',
fieldId: 'amount',
line: i
});
log.debug('Taxcode 4508 Found on Line ' + i, 'Amount: ' + amount);
// 🔁 Loop through standard lines and suppress related lines
for (var j = 0; j < standardLines.length; j++) {
var stdLine = standardLines.getLine(j);
var associatedLine = stdLine.getTransactionLine();
var type = stdLine.getLineType(); // 'debit' or 'credit'
// Suppress only lines related to the item line with taxcode 4508
if (associatedLine === i && (type === 'debit' || type === 'credit')) {
stdLine.isNonPosting = true;
log.debug('Suppressed standard ' + type + ' line', 'Line #: ' + j);
}
}
// ✅ Add custom credit line
var creditLine = customLines.addNewLine();
creditLine.accountId = 2402; // Sales - Zero Rated
creditLine.creditAmount = amount;
creditLine.memo = "Custom credit for taxcode 4508";
log.debug('Custom Credit Line Added', 'Account 401000');
// ✅ Add custom debit line
var debitLine = customLines.addNewLine();
debitLine.accountId = 2404; // PEZA
debitLine.debitAmount = amount;
debitLine.memo = "Offset Debit for taxcode 4508, line " + (i + 1);
log.debug('Custom Debit Line Added', 'Account 2404');
}
}
}
} catch (e) {
log.error("Error in customizeGlImpact", e.toString());
}
}
return {
customizeGlImpact: customizeGlImpact
};
});