getting the minimum field only calculating fields with values

Community Beginner ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

Hi

My fields are "Legal Rent" & "Pref Rent"

I want my new field "Rent Amount" to take the minimum value of the two above fields

However, if the field "Pref Rent" is blank as is the case many times I only want the new field to populate the value in "Legal Rent" and not to take the minimum in that case which is "0"

I am not so familiar with Java and I have tried pasting calculations I have found but have not been able to get anything to work for this one

TOPICS
Acrobat SDK and JavaScript

Views

138

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

Community Beginner , Jan 09, 2019 Jan 09, 2019
This worked the first time I put it in but then I changed the numbers in the fields "Legal Rent" and "Pref Rent" and although it still shows The value from "Legal Rent" when it is the only value, when I pur any number into "Pref Rent" this new field says "NAN"

Likes

Translate

Translate
Adobe Community Professional ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

You must use Javascript, not Java.

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

You can use this code as the custom calculation script of your field:

var v1 = this.getField("Pref Rent").valueAsString;

var v2 = this.getField("Legal Rent").valueAsString;

if (v1=="") event.value = v2;

else event.value = Math.min(Number(v1), Number(v2));

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
Community Beginner ,
Jan 09, 2019 Jan 09, 2019

Copy link to clipboard

Copied

This worked the first time I put it in but then I changed the numbers in the fields "Legal Rent" and "Pref Rent" and although it still shows The value from "Legal Rent" when it is the only value, when I pur any number into "Pref Rent" this new field says "NAN"

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
LEGEND ,
Jan 09, 2019 Jan 09, 2019

Copy link to clipboard

Copied

Do you have the fields' format set to numeric and are you entering the values without the thousands separator?

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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

LATEST

This works now thank you

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
LEGEND ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

You have told us what to set the Rent Amount to if Legal Rent is zero or null and there is an amount for Pref Rent. Assuming that Legal Rent need to be greater than zero, the custom JavaScript calculation for the Rent amount could be:

var LegalRent = this.getField("Legal Rent").value;

var PrefRent = this.getField("Pref Rent").value;

event.value = ""; // clear Rent Amount;

if(PrefRent == 0){

PrefRent = LegalRent; // set Prref Rent to Legal Rent value;

}

if(LegalRent != 0) {

event.value = Math.min(LegalRent, PrefRent); // select minimum of Legal Rent or Pref Rent;

}

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