I would like to ask if anyone knows how to create ...
# suitescript
c
I would like to ask if anyone knows how to create and set up a Custom GL Impact. I'm currently encountering an error that says: "TypeError: Cannot call method 'addNewLine' of undefined." I'm not sure if the issue is with my configuration. Any help would be greatly appreciated! Below is my sample script.
e
I think you're mixing 1.0 and 2.0 syntax. Being able to write Custom GL Impact plugins in 2.x is relatively new, so there's not a lot of good examples. I have not written one in 2.x yet so I was curious as well. In 2.0 it looks like your customizeGLImpact method will be passed a context object that includes the various values. So, for example, you'd need to reference customLines with something like context.customLines.addNewLine(). Take a look at this document. https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/article_8102434206.html
1
k
Hi Coleen, Here is the correct script , Please try and let me know in case of any query. ---------------------------------------------------------------- /** * @NApiVersion 2.0 * @NScriptType CustomGLPlugin */ define(['N/log'], function (log) { function customizeGlImpact(context) { try { log.debug("Running customizeGlImpact"); var customLines= context.customLines; if (!customLines) { log.error("customLines is undefined. Plugin will not proceed."); return; } var debitLine = customLines.addNewLine(); debitLine.accountId =2404; debitLine.debitAmount =0.01; debitLine.memo ="Test Debit Line"; var creditLine = customLines.addNewLine(); creditLine.accountId =1234; creditLine.creditAmount =0.01; creditLine.memo ="Offset Credit Line"; } catch (e) { log.error("Error", e.toString()); } } return { customizeGlImpact: customizeGlImpact }; });
c
Thank you @Komal Kumar it's working
🙂 1
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 }; });
image.png
basically I want my GL impact to customized if my tax code is equal to 4508
k
Hi @Coleenjae Moralidad Do you want to post only the custom GL line if the tax code is 4508 and not post the standard GL line? Please confirm
c
Hi @Komal Kumar yes i don't want to Post the standard gl line. I want to replace it to my custom gl
Hi @Komal Kumar please disregard this , I have a workaround on this. Thank you!
👍 1