Created the “Sales Rep Allocation” subtab in the payment record and implemented a validation alert to ensure that the payment total matches the amount allocated to the sales representatives.
function saveRecord(context) {
var currentRecord = context.currentRecord;
console.log("customer payment")
if (currentRecord.type === "customerpayment") {
var getLineCount = currentRecord.getLineCount('recmachcustrecord_vs_paymentsalesrep_pa');
var totalPay = currentRecord.getValue('payment');
var splitted = 0;
if (getLineCount && getLineCount > 0) {
for (var i = 0; i < getLineCount; i++) {
splitted += Number(currentRecord.getSublistValue({ sublistId: 'recmachcustrecord_vs_paymentsalesrep_pa', line: i, fieldId: 'custrecord_vs_sr_cust_amount' }));
}
if (totalPay != splitted) {
alert("The total payment of the sales reps does not match with the PA's total payment");
return false;
}
return true;
}
}
}