Within the Deductions and Chargeback SuiteApp, we ...
# ask-stanley-ai
t
Within the Deductions and Chargeback SuiteApp, we have a map/reduce script creating Small Balance Write Off credit memos. On many of our invoices that qualify for Small Balance Write Off, the script returns the following error which seems to have some relationship to the Shipping Cost of the invoice. How do I correct this or is this something that will need to be addressed by Netsuite Support? {"type":"error.SuiteScriptError","name":"TRANS_UNBALNCD","message":"Transaction was not in balance. Total = 23.32","id":"","stack":["Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js39113)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js11524)"],"cause":{"type":"internal error","code":"TRANS_UNBALNCD","details":"Transaction was not in balance. Total = 23.32","userEvent":null,"stackTrace":["Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js39113)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js11524)"],"notifyOff":false},"notifyOff":false,"userFacing":true}
c
AI generated answer (using internal Slack threads):
The error
TRANS_UNBALNCD
or
Transaction was not in balance
typically occurs when there is an imbalance in the transaction, often due to missing or incorrect values in one of the line items, tax items, shipping items, discount items, etc. This could also happen if you are modifying the transaction after it has been posted, which can cause an imbalance in the amounts due to changes in tax or other factors. In your case, it seems like the error is related to the Shipping Cost of the invoice. You might want to check if the shipping cost is correctly calculated and applied to the invoice. Also, ensure that all the necessary fields related to the shipping cost are correctly filled. If you are using a script to create the Small Balance Write Off credit memos, you might want to check the script for any errors or missing values. Make sure that the script correctly calculates and applies the shipping cost to the invoice. Here is a sample code snippet that might help you troubleshoot the issue:
Copy code
javascript
var paymentObj = record.transform({
    fromType: record.Type.INVOICE,
    fromId: invoiceId,
    toType: record.Type.CUSTOMER_PAYMENT,
    isDynamic: true
});

paymentObj.setValue({ fieldId: 'paymentoption', value: paymentMethod });
paymentObj.setValue({ fieldId: 'checknumber', value: checkNumber });
paymentObj.setValue({ fieldId: 'payment', value: paymentAmount });

var lineCount = paymentObj.getLineCount({
    sublistId: 'apply'
});

for (var i = 0; i < lineCount; i++) {
    var lineInvoiceId = paymentObj.getSublistValue({ sublistId: 'apply', fieldId: 'internalid', line: i });

    if(lineInvoiceId == invoiceId){
        paymentObj.selectLine({
            sublistId: 'apply',
            line: i            
        });
        paymentObj.setCurrentSublistValue({ sublistId: 'apply', fieldId: 'apply', value: true});
        paymentObj.setCurrentSublistValue({ sublistId: 'apply', fieldId: 'amount', value: paymentAmount });

        paymentObj.commitLine({
            sublistId: 'apply'
        });
    }
}

var paymentId = paymentObj.save();
This script transforms an invoice into a customer payment and sets the necessary values. It then loops through the line items and applies the payment to the correct invoice. If the invoice ID matches the line invoice ID, it selects the line and sets the 'apply' and 'amount' fields. Finally, it commits the line and saves the payment. Please note that this is just a sample script and might need to be adjusted according to your specific requirements. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.879516721
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.874145687
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.872375548
Please provide your feedback on this answer.