Hello, I'm trying to troubleshoot a client script ...
# suitescript
s
Hello, I'm trying to troubleshoot a client script that broke on Friday. Any reason why this would result in "Transaction is not in balance! Line item sum of $0 does not equal applied amount of $40.00." Wondering if perhaps NetSuite changed something?
Copy code
var paymentObj = record.transform({
	    	    fromType: record.Type.INVOICE,
	    	    fromId: invoiceId,
	    	    toType: record.Type.CUSTOMER_PAYMENT,
	    	    isDynamic: true
	    	});
	    	console.log('Payment Transformed');
	    	
	    	paymentObj.setValue({ fieldId: 'paymentoption', value: paymentMethod });
	    	paymentObj.setValue({ fieldId: 'checknumber', value: checkNumber });
	    	paymentObj.setValue({ fieldId: 'payment', value: paymentAmount }); //$40.00 GOOD
	    	
	    	var lineCount = paymentObj.getLineCount({
	    		sublistId: 'apply'
	    	});
  			//GOOD
	    	for (var i = 0; i < lineCount; i++) {
	    		var lineInvoiceId = paymentObj.getSublistValue({ sublistId: 'apply', fieldId: 'internalid', line: i });
                console.log('lineInvoiceId:', lineInvoiceId); //GOOD
                console.log('invoiceId:', invoiceId); //GOOD
	    		
	    		if(lineInvoiceId == invoiceId){
                  console.log('Line Invoice ID = Invoice ID'); //GOOD
                  
	    			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'
	    			});
	    		}
	    		
			}
	    	
	    	console.log('savingPayment')
	    	var paymentId = paymentObj.save(); //CONSOLE ERROR = Transaction is not in balance!  Line item sum of $0 does not equal applied amount of $40
c
Has this environment upgraded to 2023.2 since the script worked? Can you log from inside the block that starts with
if(lineInvoiceId == invoiceId)
to make sure it's reaching this and updating the line you expect?
s
2023.2 is a strong possibility. Yeah, the lineCount evaluates to 1 (only 1 apply line), so the selectLine could only be line 0/i. I will test further.
c
Sorry, I see you are already logging from that point, and you identified that as good
b
code looks reasonable, make sure it works serverside before sending it to support