Copy link to clipboard
Copied
Hi
I am trying to add formula to field that is dependent on another field. I have 3 columns.
Neutral (entry field)
Minimum (calculated field)
Maximum (calculated field)
Users can enter values in the Neutral field.
The formula I am looking for is
Minimim = if the "neutral" value is "", the "minimum" should show "" (empty)
if the "neutral" value is >=0 and < 10 , the "minimum" should show "0"
if the "neutral" value is >0, the "minimum" should show "neutral"-10
Maximum = if the "maximum" value is "", the "maximum" should show "" (empty)
if the "maximum" value is >=0, the "maximum" should show "neutral"+10
I tried adding formulas but when "neutral" = "", "minimum" always shows "0" and "maximum" always shows "10".
I would like "minimum" and "maximum" to show blank if "neutral" is blank
Hope someone can assist with this.
Thanks
You're close. However, JS will automatically convert a value to another type for you, and an empty string will be converted to zero if you use it as a number. So you need to make sure you're working with strings first.
Try this:
var neutralString = this.getField("neutral").valueAsString;
if (neutralString=="") event.value = "";
else {
var neutralValue = Number(neutralString);
if (neutralValue >= 10 ) event.value = neutralValue - 10;
else event.value = 0;
}
Copy link to clipboard
Copied
Hi NikS
Hope you are doing well and sorry for the trouble.
The workflow you are trying to achieve is possible using the JavaScript. For more information about using the JavaScript, please check the help page https://acrobatusers.com/tutorials/javascript_console/ and see if that works for you.
Regards
Amal
Copy link to clipboard
Copied
Hi Amal
Thanks for your response.
I am not too familiar with the javascript codes. Was wodering if someone can help me with that.
This is what i have for the "minimum" field
if( this.getField("neutral").value >= 10 ) event.value = this.getField("neutral").value - 10;
else event.value = 0
and this is what i have for "maximum" field
if( this.getField("neutral").value >= 0 ) event.value =
event.value = this.getField("neutral").value + 10
else event.value = ""
in both cases i would like to show empty field "" if "neutral" field is also empty. But for "minimum" I would like to see a condition where if the "neutral" value is greather than and equal to 0 and less than 10, to show 0.
Hope someone is able to help
Thanks
Copy link to clipboard
Copied
You're close. However, JS will automatically convert a value to another type for you, and an empty string will be converted to zero if you use it as a number. So you need to make sure you're working with strings first.
Try this:
var neutralString = this.getField("neutral").valueAsString;
if (neutralString=="") event.value = "";
else {
var neutralValue = Number(neutralString);
if (neutralValue >= 10 ) event.value = neutralValue - 10;
else event.value = 0;
}
Copy link to clipboard
Copied
Thank you Try67.
this worked.