Speed Issues with Assigning Row Prices, Section Totals and Grand Total
-
I have a list of products that I am assigning pricing through a function in a calculated field and the input and calculation is painfully slow.
I’ve tried this a couple ways, putting seperate functions in seperate calculated fields, setting delays, etc. with the same slow result.
Any suggestions, here is the code:
(function () {
let calculationTimeout;
// Function to assign row prices (this will be delayed)
function assignRowPrices() {
getField(73).setVal(fieldname71 * fieldname72);
getField(81).setVal(fieldname79 * fieldname80);
getField(202).setVal(fieldname200 * fieldname201);
getField(152).setVal(fieldname150 * fieldname151);
getField(158).setVal(fieldname156 * fieldname157);
getField(196).setVal(fieldname194 * fieldname195);
getField(168).setVal(fieldname165 * fieldname167);
getField(233).setVal(fieldname231 * fieldname232);
getField(238).setVal(fieldname236 * fieldname237);
getField(247).setVal(fieldname245 * fieldname246);
getField(252).setVal(fieldname250 * fieldname251);
getField(257).setVal(fieldname255 * fieldname256);
getField(269).setVal(fieldname267 * fieldname268);
getField(274).setVal(fieldname272 * fieldname273);
getField(279).setVal(fieldname277 * fieldname278);
getField(297).setVal(fieldname295 * fieldname296);
getField(304).setVal(fieldname302 * fieldname303);
getField(311).setVal(fieldname309 * fieldname310);
getField(327).setVal(fieldname345 * fieldname326);
getField(337).setVal(fieldname345 * fieldname336);
}
// Function to calculate section totals
function calculateSectionTotals() {
let totalPanels = SUM(getField(73).val(), getField(81).val()) - getField(202).val();
let totalShelves = SUM(getField(152).val(), getField(158).val()) - getField(196).val();
let totalBridge = SUM(getField(168).val(), getField(233).val()) - getField(238).val();
let totalRods = SUM(getField(247).val(), getField(252).val()) - getField(257).val();
let totalDrawers = SUM(getField(269).val(), getField(274).val()) - getField(279).val();
let totalDoors = SUM(getField(297).val(), getField(304).val()) - getField(311).val();
let totalFiller = getField(327).val() - getField(337).val();
return [
totalPanels > 0 ? totalPanels : "",
totalShelves > 0 ? totalShelves : "",
totalBridge > 0 ? totalBridge : "",
totalRods > 0 ? totalRods : "",
totalDrawers > 0 ? totalDrawers : "",
totalDoors > 0 ? totalDoors : "",
totalFiller > 0 ? totalFiller : ""
];
}
// Function to update totals
function updateTotals() {
const [totalPanels, totalShelves, totalBridge, totalRods, totalDrawers, totalDoors, totalFiller] = calculateSectionTotals();
getField(96).setVal(totalPanels);
getField(162).setVal(totalShelves);
getField(178).setVal(totalBridge);
getField(261).setVal(totalRods);
getField(283).setVal(totalDrawers);
getField(317).setVal(totalDoors);
getField(341).setVal(totalFiller);
let grandTotal = SUM(totalPanels, totalShelves, totalBridge, totalRods, totalDrawers, totalDoors, totalFiller);
getField(322).setVal(grandTotal > 0 ? grandTotal : "");
}
// Wrapper function to delay calculations without affecting quantity input
function delayedCalculation() {
clearTimeout(calculationTimeout);
calculationTimeout = setTimeout(() => {
assignRowPrices();
updateTotals();
}, 500); // Set delay for calculations to trigger only after input pause
}
// Initial calculation
delayedCalculation();
// CFF built-in listeners will handle triggering delayedCalculation()
})();
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.