Skip to main content
lancem32956364
Participating Frequently
May 20, 2019
Answered

Simple Calulation

  • May 20, 2019
  • 4 replies
  • 583 views

I have need for a simple if statement but I'm not Java savie yet.

I have  field "Percent" and "OBscore"

I would like to have a if statement that will fill in OBscore with Good or Great based on a score from Percent.

A good score 50 - 80

A great score 01 -100

Many thanks

This topic has been closed for replies.
Correct answer try67

Thanks..

It works...  except the variables Poor, good, great will not change if I change the scoring,

FOr example... It works from 0-50 for poor but will not update after that if the score increases.


If your field is set as a Percentage field under Properties - Format then the value is probably between 0 and 1, not 0 and 100.

Adjust the values in the code accordingly (so 0.5 instead of 50 and 0.8 instead of 80, basically) and it should work.

4 replies

lancem32956364
Participating Frequently
May 20, 2019

That did it... Many thanks

lancem32956364
Participating Frequently
May 20, 2019

Gradeant scores... 

A "poor" score 0-49

A "good" score 50 - 80

A "great score" 81 -100

try67
Community Expert
Community Expert
May 20, 2019

OK, that's better. You can use this code as the custom calculation script of "OBscore":

var score = Number(this.getField("Percent").valueAsString);

if (score<50) event.value = "Poor";

else if (score<=80) event.value = "Good";

else event.value = "Great";

lancem32956364
Participating Frequently
May 20, 2019

Thanks..

It works...  except the variables Poor, good, great will not change if I change the scoring,

FOr example... It works from 0-50 for poor but will not update after that if the score increases.

lancem32956364
Participating Frequently
May 20, 2019

Sorry.. Correction

A good score 50 - 80

A great score 80 -100

try67
Community Expert
Community Expert
May 20, 2019

Now 80 falls in both categories...

try67
Community Expert
Community Expert
May 20, 2019

Also, what should the field show if the score is below 50?

try67
Community Expert
Community Expert
May 20, 2019

That doesn't make much sense... All of the "Good" scores fall within the "Great" range as well.

And it's JavaScript, not Java.