Copy link to clipboard
Copied
Hi All!
So I've been googling, but I think I don't fully understand how to tell javascript what I want to do.
I'm trying to get a total in Field4 based on three other fields, Field1, Field2, Field3.
If Field 3 is blank, I want the minimum of Filed 1 and Field 2. Otherwise, I want the maximum.
var a = this.getField("Field1");
var b = this.getField("Field2");
var c = this.getField("Field3");
if (c==="") {
Math.min(a,b);
} else {
Math.max(a,b);
}
When I put that in, it gives me 0. For reference, Field1 = 7, Field2 = 9, and Field3 is blank on my form. So I'd be hoping the calculation would show 7, and would change to a 9, if I put a "1" in Field3.
I know what I'm missing has got to be simple or an inherent misunderstanding of javascirpt, but I can't for the life of me figure it out.
Copy link to clipboard
Copied
Try this:
var a = this.getField("SPI").value;
var b = this.getField("WLL").value;
var c = this.getField("Rank1").value;
if (c==="") {
event.value=Math.min(a,b);
} else {
event.value=Math.max(a,b);
}
Copy link to clipboard
Copied
You also need to assign min and max to event field as pointed by @PDF Automation Station
Copy link to clipboard
Copied
Use like this:
var a = this.getField("Field1").value;
var b = this.getField("Field2").value;
var c = this.getField("Field3").value;
if (c==="") {
Math.min(a,b);
} else {
Math.max(a,b);
}
if you use like this:
var a = this.getField("Field1");
var b = this.getField("Field2");
var c = this.getField("Field3");
then need to add values like this:
if (c.value==="") {
Math.min(a.value,b.value);
} else {
Math.max(a.value,b.value);
}
Copy link to clipboard
Copied
Thank you so much!
I pasted your first example, and changed out the actual field names in my file (pasting them as they are in my file this time, in case that's part of the problem)
var a = this.getField("SPI").value;
var b = this.getField("WLL").value;
var c = this.getField("Rank1").value;
if (c==="") {
Math.min(a,b);
} else {
Math.max(a,b);
}
The field calculates blank, now.
SPI=7 on my form (Field1)
WLL = 9 on my form (Field2)
Rank1 = whether it's blank or has a number in it, the field (Field3)
ART = Regardless of whether Rank1 is blank, 0, or 1, ART is staying blank (Field4)
Is making Rank1 a value somehow negating that it's blank in javascript?
Copy link to clipboard
Copied
Here's what the Java Script Editor for the field looks like
Copy link to clipboard
Copied
Try this:
var a = this.getField("SPI").value;
var b = this.getField("WLL").value;
var c = this.getField("Rank1").value;
if (c==="") {
event.value=Math.min(a,b);
} else {
event.value=Math.max(a,b);
}
Copy link to clipboard
Copied
Thank you so much! It made it work immediately!
Copy link to clipboard
Copied
You also need to assign min and max to event field as pointed by @PDF Automation Station
Copy link to clipboard
Copied
Thank you so much! It would probably have been helpful if I'd shown a screenshot to begin with so you could see what "obvious bits" I was missing. 🙂
I truly appreciate you looking over this for me!
Copy link to clipboard
Copied
this.getField("Field1") calls the field object. You need to call the value of the field object like this:
this.getField("Field1").value
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more