You are viewing limited content. For full access, please sign in.

Question

Question

How to Prevent Laserfiche Table Calculation from Erasing Quantity Values When Adding New Rows

asked on October 22, 2024

Good day,

I have a Laserfiche form that includes a table with the columns: Product Name, Product License, and Product Quantity. I've applied a calculation to the Quantity field using the following formula:

=IF(INDEX(Table_Data.License, ROW()) = "Account", 1, 0)

This formula updates the Quantity to 1 if the License field contains "Account" and sets the Quantity to 0 for any other value in the License field. While the formula works as expected, I encounter an issue when adding a new row to the table—it erases all previously entered values in the Quantity column.

Does anyone know how I can prevent this from happening?

0 0

Answer

APPROVED ANSWER
replied on October 24, 2024 Show version history

Unfortunately, right now that is how formulas work in both designers. Any formula that references a field in a table/collection regardless of row recalculates when the table state changes. This is something we are looking into, but there are cases where you DO want this behavior so its not as simple as just fixing it. 

 

For now you can use JS to handle the formulas and these will bypass row add/delete 

const fields = {
  sourceCalcFieldCol: { fieldId: 7 },
  destCalcFieldCol: { fieldId: 8 }
};
// Do some calculation
const performCalculation = (sourceVal) => {
  return sourceVal * 2;
};
// Handle calculation change events
const handleCalculationChange = async (index) => {
  if (index) {
    const sourceValSingle = LFForm.getFieldValues({
      ...fields.sourceCalcFieldCol,
      index
    });
    return LFForm.setFieldValues(
      { ...fields.destCalcFieldCol, index },
      performCalculation(sourceValSingle)
    );
  }
  const sourceValList = LFForm.getFieldValues(
    fields.sourceCalcFieldCol
  );
  const sourceValAsList = Array.isArray(sourceValList) ? sourceValList : [sourceValList];
  const destVal = sourceValAsList.map((val) => performCalculation(val));
  return LFForm.setFieldValues(fields.destCalcFieldCol, destVal);
};
const main = async () => {
  // register change events
  LFForm.onFieldChange(async (e) => {
    const fieldsChanged = e.options;
    for (const row of fieldsChanged) {
      const index = row.index;
      await handleCalculationChange(index);
    }
  }, fields.sourceCalcFieldCol);
  // initial calculations
  await handleCalculationChange();
};
main().catch(console.warn);

 

0 0

Replies

replied on April 8

Hi, this issue has been fixed on Forms 12 Spring 2025 Release: Remove row will not retrigger the field formula again. (BugID: 538524)

You can see other changes from: Laserfiche 12 Release Information

Get the latest Laserfiche Forms 12 package from: Laserfiche 12 - Downloads

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.