Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Level 2

## Autopopulate Percentage box

I am trying to get a percentage box added to my form where the percentage difference between the old and new salary is populated based on the old and new bi-weekly salarys. This is a general idea of what I am looking for:

 Old Bi-weekly Salary (entered by user) Annual Salary (Autopopulates biweekly salary *26) New Bi-Weekly Salary (entered by user) Annual Salary (Autopopulates biweekly salary *26) Percentage Difference (need to populate % diff based on difference between old and new salaries)

Can someone please help me to get this to work? I cant seem to get it to work without messing up my autopopulated annual payout field.

Misti

3 Replies

Level 10

I always have to look up percentages...found a good page here on calculating percentage change: http://www.mathsisfun.com/numbers/percentage-change.html

So basically the new value divided by the old value times 100 then subtract 100.

Using FormCalc on the Calculate event of the field:

`if (HasValue(newSalaryField) & HasValue(oldSalaryField)) then((newSalaryField/oldSalaryField) * 100) - 100endif`
In the Display pattern for your field you want num{zz9'%'} and click the Allow Zero checkbox.
That should do the trick!

Level 10

Hi,

First make sure that the percentage object is a numericField.

if we work on the basis that the objects are named "oldSalary" and "newSalary", then the following JavaScript in the calculate event of the percentage object should work:

`// first check that neither salary object is nullif (oldSalary.rawValue != null && newSalary.rawValue != null){     this.rawValue = (newSalary.rawValue - oldSalary.rawValue) / oldSalary.rawValue; }`

Then in the Object > Field palette, click on the Patterns button. There is a percentage display pattern, which you can select and then adjust to how many decimal places you want it display to.

Hope that works/helps,

Niall

It's like busses, you wait for ages and then two come along at the same time

Level 2

Oh my gosh!!! It worked!! Thank you so much for your help!!!!!