Can I change the Invoice Line Account?
Hi!
We need to change the invoice line account based on some conditions. This value is defaulted from the Item setup; but in some scenarios we need a different account than the one that comes from the Item.
We tried this in before and after submit actions, with setValue and setText but nothing is working. The odd here is that I don’t get any error; I see in logs that I correctly change the value but then that value is not saved.
This is the account we want to change:
This is the log after saving the invoice, you can see that the account is correctly updated to the new ID.
But when I go to the GL Impact again I keep seeing the “40100” account instead of “40200”.
This is the 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 }; });
I tried different ways in before and after submit. I also used setSublistText instead of setSublistValue, nothing works. Some other ways I tried:
invoiceRecord.setSublistText({ sublistId: 'item', fieldId: 'account', line: i, text: '40200 Revenue : WCD Revenue' });
invoiceRecord.setSublistText({ sublistId: 'item', fieldId: 'account', line: i, text: '1037' });
Any idea what is wrong here? It calls to my attention that the GL Impact tab dissapears on edit mode, so I have to ask are we able to change this account?
Thanks





