Custom GL Plug-In in SuiteScript 2.1. Using conte...
# ask-stanley-ai
j
Custom GL Plug-In in SuiteScript 2.1. Using context.customLines.addNewLine() and then setting attributes of the new custom line. Script does not error, but no GL Lines get added.
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems like you're trying to add custom GL lines using SuiteScript 2.1. However, you're not seeing any errors, and yet the GL lines are not being added. One possible issue could be that you're not correctly referencing the
customLines
object. In SuiteScript 2.x, the
customizeGLImpact
method is passed a context object that includes various values. You should reference
customLines
with something like
context.customLines.addNewLine()
. Here's a sample script that might help:
Copy code
javascript
/**
 * @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
    };
});
This script first checks if
customLines
is defined. If it is, it adds a new debit line and a new credit line with static values. If
customLines
is not defined, it logs an error and does not proceed. Remember to ensure that your plugin is correctly set up and that all necessary fields (like the subsidiary field) are correctly filled in. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.855896056
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.848327696
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.843139768
Please provide your feedback on this answer.