8 Replies Latest reply on Jul 25, 2014 8:33 AM by DLMAce

# If field is not blank, add value

• ###### 1. Re: If field is not blank, add value

To what do you want to add this value, exactly? How is the target field currently calculated?

• ###### 2. Re: If field is not blank, add value

Hi Gilad, thanks for your help.  The target field is the sum of 2 fields (A & B for example).  If those fields are blank or 0, there should be nothing, or 0 showing in the target field.  If fields A & B contain a value, the target field would equal A+B+25.  Does this make sense?

• ###### 3. Re: Re: If field is not blank, add value

You can use this code as the custom calculation script of this field, then:

```var a = this.getField("A").valueAsString;
var b = this.getField("B").valueAsString;
if (a && b) {
event.value = Number(a) + Number(b) + 25;
} else event.value = "";
```
• ###### 4. Re: If field is not blank, add value

This is very helpful, thank you!  I tried this, and both A and B are 0, but the field is showing 25. If A & B are 0, I need it to output 0.  Am I doing something wrong?

• ###### 5. Re: If field is not blank, add value

You need to define exactly how it should work, when:

- A is blank, B is blank

- A is blank, B is zero

- A is blank, B has a value

- A is zero, B is blank

- A is zero, B is zero

- A is zero, B has a value

- A has a value, B is blank

- A has a value, B is zero

- A has a value, B has a value

• ###### 6. Re: If field is not blank, add value

Thank you again, I think I am approaching this problem from the wrong direction.  I think it may be easier to assign a value of 25 to a check box, and if that is checked 25 will be added to the sum of A + B + checkbox-value.

I've added this to the checkbox-value:

var a =""

if (this.getField("checkbox").value == "Yes")

{

a="25"

}

event.value=a

Then I am using the sum of A + B + checkbox-value in the output field.  The problem is that it's adding 25 when it's not checked, and adding nothing when it is?

• ###### 7. Re: If field is not blank, add value

If the export value of the check-box is set as "25" then you don't need any code. Just include it in the calculation script of the text field directly.

• ###### 8. Re: If field is not blank, add value

Wow, that was easy   I'm feeling like a dummy now, guess it's the lack of sleep from two sick kids this week!  Thank you so much.