7 Replies Latest reply on May 13, 2015 9:07 AM by metaljda

# I need to calculate a formula in one field, only if another field is filled in first

I have 3 fields that need to interact with eachother.  "VNP1" needs to calculate "ColumnInches" x 14 x .395, but only when "VNRD1" is filled in.  How would I do that with javascript?

• ###### 1. Re: I need to calculate a formula in one field, only if another field is filled in first

Use this code as the custom calculation script of VNP1:

```if (this.getField("VNRD1").valueAsString=="") event.value = "";
else event.value = Number(this.getField("ColumnInches").value) * 14 * 0.395;
```
• ###### 2. Re: I need to calculate a formula in one field, only if another field is filled in first

Thanks for your help!  Works perfectly!

• ###### 3. Re: I need to calculate a formula in one field, only if another field is filled in first

How would I get this to show a rounded number to 2 decimal places? For example 3.5691033 to round to 3.57

• ###### 4. Re: I need to calculate a formula in one field, only if another field is filled in first

Set the Format option of the field to Number with 2 decimals.

• ###### 5. Re: I need to calculate a formula in one field, only if another field is filled in first

Yes, I just figured that out...thanks again for your help.

• ###### 6. Re: I need to calculate a formula in one field, only if another field is filled in first

For the display value or the actual value of the field?

For the display use the format tab.

For the actual values of the field, you will need to use a script to set the field's value to the rounded value.

For many accounting forms it is important to round the actual value of the field because the mils will accumulate and can cause any computed grand total to exceed the total of the displayed values or expected accounting sum of the format field values.

• ###### 7. Re: I need to calculate a formula in one field, only if another field is filled in first

Yes, I figured out that it was on the format tab shortly after I posted.  Thanks!