Must set amount when set line-item quantity? -----...
# suitescript
j
Must set amount when set line-item quantity? ------------------------------------------- On the sales order line, I am calculating and setting the quantity column based on values entered by the user in several other, custom columns. I am using the fieldChanged entry point for these custom columns to trigger the calculation and "set" of the quantity. The answer to this question may seem obvious, but should I expect that I also need to re-calculate and set the amount if I want it to equal quantity * rate? Before I code this, just want to make sure I am not missing something.
s
depending on the record, you will not even be able to set
amount
. You may have to set rate/quantity allowing NS to calculate amount.
I don't recall off the top of my head if sales orders are one such record or not.
j
Thanks. I was able to set the rate in the debugger, but the amount does not recalculate upon return to the UI.
s
if you do have to set
amount
be careful with javascript rounding. We typically use BigNumberJs to give us more flexibility in this regard.
j
Good advice, thank you.
As you hinted, my attempt to set amount in the fieldChanged event was unsuccessful. Do you happen to know whether it's possible to set amount in the client saveRecord or UE beforeSubmit events? Wouldn't result in the best user experience, but it would get the job done.
s
If this needs to be a client script for UX reasons, I'd try harder with the
rate
setting. Make sure you're doing it after other fields have sourced, or use the 'forcesyncsourcing' option. Changing an item on the line, for example, could change the rate as it pulls that value in.
j
Thanks for your help. You pointed me in the right direction. Found the underlying problem was an error of mine. Earlier I was having issues with field validation and had set ignoreFieldChange to true in the function I use to set sublist values. Went there to try forceSyncSourcing, per your advice, and saw ignoreFieldChange was still true. Removed it, and now am getting the expected behavior.
👍 1