Post

3 followers Follow
0
Avatar

If else statement - using value from one field if used, else use another fields value

Hi, I am trying to figure out how to solve an issue regarding some calculations. Basically I need a calculation to take the value from one field, if that field is used, or else i need the value from another field.

So, If Field1 is filled out with Value1, I need Value1 to be the value that the calculation is using, otherwise if Value1 is equal to 0 or nothing, the calculation has to take Value2 from Field2, and use that amount in the rest of the calculation.
Is that possible?

Thanks in advance

Jacob Heydenreich Jensen

Please sign in to leave a comment.

3 comments

0
Avatar

Hi Jacob,

you can do this:

var field1 = @field1;
var field2 = @field2;
var numberToUse = field1 == null || field1 == 0 ? field2 : field1;

Then use the variable in your calculation, like 
10 + numberToUse / 5

Rainer 

Rainer Grabowski 0 votes
Comment actions Permalink
0
Avatar

Viva Jacob.

Tente: 

if (@Campo1 == null) {
@Campo 2;
} else {
@Campo1;
}

Abraço 

 

Claudio Sambuta 0 votes
Comment actions Permalink
0
Avatar

Thank you very much guys :) 
It worked! 

Jacob Heydenreich Jensen 0 votes
Comment actions Permalink