Hi! I need to change the account in the invoice li...
# suitescript
l
Hi! I need to change the account in the invoice line with any suitescript. Are we able to do that? In the online on edit mode the GL Impact where the account is just disappears so I'm trying to use a before submit but it is not doing anything. It changes the value but then it is not saved in the account.
Copy code
/**
 *@NApiVersion 2.1
 *@NScriptType UserEventScript
 */
 
 
define(['N/record', 'N/log'],
 
    (record, log) => {
 
        const beforeSubmit = (context) => {
            log.debug('L 2');
            var invoiceRecord = context.newRecord;
            try {
                var numLines = invoiceRecord.getLineCount({
                    sublistId: 'item'
                });
 
                for (var i=0; i < numLines; i++) {
                    var currentAccount = invoiceRecord.getSublistText({
                        sublistId: 'item',
                        fieldId: 'account',
                        line: i
                    });
                    log.debug('current Account', currentAccount);
 
                    invoiceRecord.setSublistValue({
                        sublistId: 'item',
                        fieldId: 'account',
                        line: i,
                        value: 1037
                    });
 
                    var newAccount = invoiceRecord.getSublistValue({
                        sublistId: 'item',
                        fieldId: 'account',
                        line: i
                    });
                    log.debug('new Account', newAccount);
                }
 
            } catch (exception) {
                log.debug(invoiceRecord.id + "-" + exception.message ? exception.message : exception);
            }
        }
 
        return {
            beforeSubmit: beforeSubmit
        };
    });
this is the log showing the value is changed
this is the account that is actually not changed