I need to get the Remaining Balance of all Customer Deposits linked to a specific Sales Order
Remaining Balance = the available/unapplied amount
Below, I will show you how I solved this in a saved search. As a bonus, I'll also include the SuiteScript 1.0 code to do the same.
To show the Remaining Amount of all Customer Deposits linked to a specific Sales Order record:
Create a Transaction Saved Search as follows:
Criteria (Use Expressions)
Results
BONUS, SuiteScript 1.0 code to get Remaining Amount of all Customer Deposits linked to a specific Sales Order record:
function customerDepositsRemainingBalance(salesorder_internalid) {
var filters = [[["type","anyof","DepAppl"],"AND",["createdfrom.salesorder","anyof",salesorder_internalid]],"OR",[["type","anyof","CustDep"],"AND",["createdfrom","anyof",salesorder_internalid]]];
var columns = [new nlobjSearchColumn('formulanumeric',null,'SUM')];
columns[0].setFormula("CASE WHEN {type} = 'Customer Deposit' THEN {debitamount} ELSE -{creditamount} END");
var search = nlapiSearchRecord('transaction',null,filters,columns);
if(search == null) return 0;
return Number(search[0].getValue(columns[0]));
}
// Example Usage
balance = customerDepositsRemainingBalance(3247434); // returns 50
balance = customerDepositsRemainingBalance(3256644); // returns 0