Custom GL plugin for add requester name against the default account in GL line

/**
 * Function to add requester name against the default account in GL line
 * @param transactionRecord : Curresponding transaction record
 * @param standardLines : Contains an array of all standard lines with GL impact in a transaction
 * @param customLines: Contains an array of all custom lines with GL impact in a transaction
 */

function customizeGlImpact(transactionRecord, standardLines, customLines) {

    try {

        nlapiLogExecution("DEBUG", "data", JSON.stringify(transactionRecord))
        var requesterName = transactionRecord.getFieldValue('custbody_empadv_requestor');
        for (var i = 0; i < standardLines.getCount(); i++) {
            var line = standardLines.getLine(i);
            var accountId = line.getAccountId();

            // Check if the account ID matches 114
            if (accountId === 114) {
                var amount = line.getDebitAmount();
                // Add credit entry
                var newCreditLine = customLines.addNewLine()
                newCreditLine.setAccountId(114); // Set the account for credit entry
                newCreditLine.setCreditAmount(amount); // Set the credit amount
                // Add debit entry
                var newDebitLine = customLines.addNewLine() // Insert a line after the identified line
                newDebitLine.setAccountId(114); // Set the account for debit entry
                newDebitLine.setDebitAmount(amount); // Set the debit amount
                newDebitLine.setEntityId(Number(requesterName))
            }
        }
    } catch (e) {

        nlapiLogExecution('ERROR', 'Error @ customizeGlImpact', e.message);

    }
}

Leave a comment

Your email address will not be published. Required fields are marked *