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

Question

Question

Use advanced calculation on a row in a table

asked on September 23, 2024

I need a way to do a very simple calculation on one of the rows in my table. The forms user will input the monthly base salary in both columns (current and effective), they will also input manually the PI Pay amounts. I was trying to allow the forms user to skip the annual base salary row because it is simply whatever was input on the monthly row above times twelve (*12).

 

The name of the table is:

Salary_Schedules

Column 1 are the row titles

  • Monthly Base Salary
  • Annual Base Salary (the row I need to calculate *12 from "Monthly Base Salary")
  • Annualized PI Pay Amt

 

Column 2  Current_Salary_Schedule_Monthly "Current Compensation"

Column 3 New_Salary_Schedule_Monthly "Compensation Effective"

When I view the variables of this table in variable management, the only thing I can see is the column headers as variables, not what each "cell" variable name or field ID would be.

Would this need to be handled via Java script or CSS?

My only other option is to bail on the look of the table all together and use single line fields and currency fields independently, which is fine, but was hoping to keep the clean look of the table if possible.

Thank you community in advance for any and all input!

0 0

Replies

replied on September 24, 2024

Your best option here would be to use JavaScript because any formula you put into the table that needs a previous rows value would be a circular reference. You could use the following function to do your math, just update the first variable to the field Id of the comp fields

const currentCompFieldId = 58;
const compEffectiveFieldId = 59;
LFForm.onFieldBlur(
  async (e) => {
    const rowNum = e.options[0].index;
    if (rowNum !== 0) return;
    const [monthlyComp, annualComp, piComp] = LFForm.getFieldValues({
      fieldId: currentCompFieldId,
    });
    await LFForm.setFieldValues(
      { fieldId: currentCompFieldId, index: 1 },
      12 * monthlyComp,
    );
  },
  { fieldId: currentCompFieldId },
);
LFForm.onFieldBlur(
  async (e) => {
    const rowNum = e.options[0].index;
    if (rowNum !== 0) return;
    const [monthlyComp, annualComp, piComp] = LFForm.getFieldValues({
      fieldId: compEffectiveFieldId,
    });
    await LFForm.setFieldValues(
      { fieldId: compEffectiveFieldId, index: 1 },
      12 * monthlyComp,
    );
  },
  { fieldId: compEffectiveFieldId },
);

 

0 0
replied on September 24, 2024

@████████ Yes! I was worried about that exact issue, the circular reference. I will get started on applying this script and let you know, thank you!

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

Sign in to reply to this post.