Good day mates, I'm trying to work on a custom GL ...
# suitescript
a
Good day mates, I'm trying to work on a custom GL plugin that checks for all the GL lines and if it does not match the main line location, It would create lines to point the amount to the same location as the main line. I am writing the custom GL plugin using SS2.x and has been following the guide found in SuiteAnswers. Now I have encountered this weird behavior where in if I am using loops to get line details, it just returns me the detail for line 0 (main line). But using the get line outside of a loop and feeding it a static value gives the actual line detail for whichever index was used.
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType customglplugin
 */
define([
    'N/record'
    ],
    /**
     * @param {record} record
     */
    function (
        record
    ) {
        function reclassifyInterBranchInvoicesToMainLocation(scriptContext) {
            try {
                const invoiceRecord = scriptContext['transactionRecord'];
                const standardLines = scriptContext['standardLines'];
                const customLines = scriptContext['customLines'];

                const transactionType = invoiceRecord['type'];

                const mainlineLocationId = invoiceRecord.getValue({
                    fieldId: 'location'
                });

                const standardLinesCount = standardLines.count;

                log.audit({
                    title: 'Details',
                    details: {
                        mainlineLocationId: mainlineLocationId,
                        standardLinesCount: standardLinesCount
                    }
                });
                const standardLinesArr = [];
                for (var i = 0; i < standardLinesCount; i++) {
                    const standardLine = standardLines.getLine({
                        index: i
                    });
                    standardLinesArr.push(standardLine)
                }

                const manualStandardLineArr = [];
                const line1 = standardLines.getLine({
                    index: 0
                });
                manualStandardLineArr.push(line1);
                const line2 = standardLines.getLine({
                    index: 1
                });
                manualStandardLineArr.push(line2);
                const line3 = standardLines.getLine({
                    index: 2
                });
                manualStandardLineArr.push(line3);
                const line4 = standardLines.getLine({
                    index: 3
                });
                manualStandardLineArr.push(line4);
                const line5 = standardLines.getLine({
                    index: 4
                });
                manualStandardLineArr.push(line5);
                const line6 = standardLines.getLine({
                    index: 5
                });
                manualStandardLineArr.push(line6);

                log.audit({
                    title: 'Standard Lines',
                    details: standardLinesArr
                });
                log.audit({
                    title: 'Manual Standard Lines',
                    details: manualStandardLineArr
                });

                if (transactionType === record.Type.INVOICE) {
                    log.audit({
                        title: 'TRIGGER INVOICE RECLASS HERE'
                    });
                }
            } catch (errorObj) {
                log.error({
                    title: 'Error in reclassifyInterBranchInvoicesToMainLocation',
                    details: errorObj
                });
            }
        };

        return {
            customizeGlImpact: reclassifyInterBranchInvoicesToMainLocation
        };

});
I'm hoping to actually makes this work on SS2.x, but if there's no way around it, I'll just have to make it using SS1.0 As for the logs, here's what I am getting (tabularized for easier comparison):