3 Replies Latest reply on Jun 30, 2015 9:30 AM by try67

# Need help with a script (o-o8)*a , show blank if no data

Hi all i need help with a script as i cant find an example.

I'm trying to subtract 2 numbers and then multiply that product. (o-o8)*a but i only want it to do the calculations if all the fields have numbers i.e field o , field o8 and field a.

i thank you in advance. i have been stuck on this for days searching the internet.

• ###### 1. Re: Need help with a script (o-o8)*a , show blank if no data

Assuming you want to assign the result of this calculation to another text field, use this code as that field's custom calculation script:

```var o = this.getField("o").valueAsString;
var o8 = this.getField("o8").valueAsString;
var a = this.getField("a").valueAsString;
if (o!="" && o8!="" && a!="") event.value = (Number(o)-Number(o8))*Number(a);
else event.value = "";
```
• ###### 2. Re: Need help with a script (o-o8)*a , show blank if no data

Thank you Mr. Try67 you are the man, that worked great and i was able to adjust it for all of my other formulas. if you have time please explain the code so i can understand the script. as right now im just changing the text field name but completely understanding the script.

• ###### 3. Re: Need help with a script (o-o8)*a , show blank if no data

You're welcome.

It's pretty simple, really. Lines 1-3 collect the values of the fields to variables. Line 4 checks whether all the variables are not empty, and if that's the case performs the calculation and applies it to the field using the "event.value" property.

Line 5 is for the scenario where one (or more) of the values is empty, in which case it applies an empty string as the field's new value.