Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Calculation - only calculate if a cell has value or else leave it blank

New Here ,
Aug 24, 2021 Aug 24, 2021

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

 

 

 

TOPICS
JavaScript, PDF forms

Views

42

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Aug 24, 2021 Aug 24, 2021
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; }

Likes

Translate

Translate
Adobe Employee ,
Aug 24, 2021 Aug 24, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 24, 2021 Aug 24, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 24, 2021 Aug 24, 2021

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;
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

LATEST

Thank you Try67.

 

this worked.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines