I'm running into this error with a backend suitele...
# suitescript
b
I'm running into this error with a backend suitelet when trying to create sales orders with amounts that have cents -- e.g. an amount of 1.50 works, but an amount of 1.51 creates this error.
Error trying to submit sales order record. Error: Code: TRANS_UNBALNCD Details: Transaction was not in balance. Total = -0.01
I must be missing something simple but I can't figure it out. This is my code:
Copy code
var record = nlapiCreateRecord('salesorder');

// setting other required fields here

record.setFieldValue('orderstatus', 'B');

record.selectNewLineItem('item');
record.setCurrentLineItemValue('item', 'item', 242);
record.setCurrentLineItemValue('item', 'linenumber', '1');
record.setCurrentLineItemValue('item', 'quantity', '1');

record.setCurrentLineItemValue('item', 'price', '-1'); // custom price level
record.setCurrentLineItemValue('item', 'rate', 3144.71);
record.setCurrentLineItemValue('item', 'amount', 3144.71);

record.commitLineItem('item');

record.setFieldValue('billingschedule', '1');
record.setFieldValue('paymentmethod', '1'); // Check
record.setFieldValue('otherrefnum', 123);


try {
	var salesorderID = nlapiSubmitRecord(record);
}
catch (e) {
	nlapiLogExecution('Error', 'Error', e);
}
c
don’t set the amount, as it calculates it from the rate and quantity
🙌 1
b
make the same transaction in the ui first
paying extra attention to any discounts and taxes
b
Thanks @CD, that was it! 🥳 Not sure why setting the amount would result in 1 cent less than the item total just in some cases, but not setting it seems to have fixed the problem. Great.
@battk Are you saying that trying the same code in the UI (through browser console) would be a way to debug this?
c
Yeah, you should always do the UI thing first, then you know if it’s a problem specific to your code. Set things in the same order you would in your code
👍 1
b
I appreciate it. I don't work on the UI side that much anymore, but I can see how for code generating transactions this could be useful to test in the UI. Especially considering that I can't reproduce the issue in the script debugger (but I can in a little scheduled script). In hindsight it makes sense not to set the total. 🫣
n
I could be wrong but I think it was being suggested you enter the transaction directly through the UI paying attention to what you enter and what is generated/auto-populated by NS to see where you may be going wrong / missing something, not running your code in the console.
👍 2