Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

If/else if/else syntax question

BonnyS0121
Level 1
Level 1

I am trying to write a (java) script where the value of the field would be determined by the value of another field.  For instance, if field1 is less than or equal to 50000, then 0 would be in field2,...else if field 1 is greater than or equal to 100000, then 0 would be in field 2....else field2 would be a calculated field (Field1*20/1000).

The actual script I used is:

if (RenoCost <= 50000)

{NumericField3 =="0"

}

else if (RenoCost >= 100000)

{NumericField3 == "0"

}

else

{

NumericField3 == "RenoCost*23/1000

}

Thanks

Bonny

1 Reply
yvindevogel
Level 2
Level 2

You are mixing things up here

First of all, assignment of values in JS is done with a single =, not with 2.  So, your NumericField3 == "0" is a logical expression, not an assignment.

Second, RenoCost and NumericField3 are objects.  You must ask for the value of the object using object.rawValue.

So, what I would do is this:

In the calculate event of NumericField3

var reno = (0 + RenoCost.rawValue) // rawValue returns a string

var calcValue = 0

if ( reno > 50000 && reno < 100000 ) {

  calcValue = reno * 23 / 100 ;

}

// this last line tells the event what to put in the field, it looks a bit weird, but that is the way to do it in the calculate event, the last line is just a value/variable

calcValue