šļø Effortlessly update totals based on subrecord changes.
1. Overview
This Interaction is designed to update parent totals whenever there are updates or changes in the subrecord items.
2. Example
In the below example, the function calculates new values for the parent or overall totals (subtotal, tax total, and total) by aggregating data from the "general-consultants-order-items" subrecord.
async function handler(C) {
const lineValues = C.state.subValues["general-consultants-order-items"];
const newNet = lineValues.map((v) => +v.amount).reduce((agg, v) => agg + v, 0);
const newTax = lineValues.map((v) => +v.tax).reduce((agg, v) => agg + v, 0);
const newTotal = lineValues
.map((v) => +v["gross-amount"])
.reduce((agg, v) => agg + v, 0);
const returnValue = C.mergeAll(
C.setValue("subtotal", newNet),
C.setValue("tax-total", newTax),
C.setValue("total", newTotal),
);
return returnValue
}š Need Help?
