I would like to use the standard NetSuite 'SubTotal' functionality in conjunction with some custom scripting in order to work out discount values based on the subtotal of lines above.
However, it seems that SubTotal lines only show a value once the line is committed (it shows 0 when entering the line), and I'm assuming that my 'ValidateLine' script is running before the line is committed.
Is there any kind of 'AfterSubmit' type option that can be used with ValidateLine scripts? Or any other way to determine the value of the SubTotal within the ValidateLine action?
If not, is there any way to replicate the 'SubTotal' functionality within SuiteScript (i.e. to add up all the lines above - but only up to the previous SubTotal)?
I did consider using the ValidateLine script to total each line as it is added (and include a flag to reset the total when a SubTotal is added), but I can see this causing issues with lines being edited etc....
Do I need to 'commit' the line first? But if so, how do I then access the values from that committed line? I am currently using code such as:
var subTotal = thisRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount'
});
It seems that 'getCurrentSublistValue' won't work after the line is submitted.
Is there a 'getPreviousSublistValue' command or similar? Or do I need to determine the current sublist line number and then get details from the previous line using that?