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
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"
Copy link to clipboard
Copied
You must use Javascript, not Java.
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));
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"
Copy link to clipboard
Copied
Do you have the fields' format set to numeric and are you entering the values without the thousands separator?
Copy link to clipboard
Copied
This works now thank you
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;
}