Copy link to clipboard
Copied
(JJPC MCKTOTAL1 + JDPC MCKTOTAL1)/2
Can someone provide a Script for me to evaluate?
Thank you
The basic structure of the script would be:
var v1 = Number(this.getField("FieldName1").valueAsString);
var v2 = Number(this.getField("FieldName2").valueAsString);
event.value = (v1+v2)/2;
Copy link to clipboard
Copied
You could put your calculation into the "Simplified Field Notation" method option.
If I remember correctly adding a number to itself and dividing by 2 will result in the number.
Have you looks at any of the free tutorials or videos on form creation?
Copy link to clipboard
Copied
If the field names contain spaces, though, you'll need to escape them, like this:
JJPC\ MCKTOTAL1
Copy link to clipboard
Copied
Thank you. The two fields are different; they have different names. I can't use the simplified field because it doesn't have secondary functions; e.g. it will add ONLY, but will not then divide.
I'm an advanced form creator, except when it comes to JavaScript.
I've searched all over the internet for this script, but all I get is simple tutorials that do not provide the structure of the entire syntax with all the {,},; etc. I don't know how to structure the script properly.
Copy link to clipboard
Copied
The basic structure of the script would be:
var v1 = Number(this.getField("FieldName1").valueAsString);
var v2 = Number(this.getField("FieldName2").valueAsString);
event.value = (v1+v2)/2;
Copy link to clipboard
Copied
It worked! Thank you.
var v1 = Number(this.getField("JJPC_MCKTOTAL1").valueAsString);
var v2 = Number(this.getField("JDPC_MCKTOTAL1").valueAsString);
event.value = (v1+v2)/2;
Copy link to clipboard
Copied
So, the above script works but I just figured out that I need the event.value to only calculate if v2 is >0. I tried this but it didn't work. Any assistance is appreciated.
var v1 =
Number(this.getField("JJPC_MCKTOTAL1").valueAsString);
var v2 =
Number(this.getField("JDPC_MCKTOTAL1").valueAsString);
event.value = If((v2>0),(v1+v2)/2,v1);
Copy link to clipboard
Copied
What should be the value of the field if that condition is not true?
Copy link to clipboard
Copied
If V2>0, then add v1+v2, if it is false, then v1.
Is that what you're asking?
Thanks
Copy link to clipboard
Copied
I've derived this formula that works for 5 of 6 fields. On the 6th field it is a one adjustment calculation delayed (I have 5 Y/N drop down list options that get calculated in a field, one for the first 6mths, then on another field for the second 6 mths).
What's wrong with this?
var v1 =
Number(this.getField("JJNotesCompletionRate").valueAsString);
var v2 =
Number(this.getField("JDNotesCompletionRate").valueAsString);
if(v2>0) {
event.value = (v1+v2)/2;
} else {
event.value = v1;}
Copy link to clipboard
Copied
Thr code is fine. The issue is with the Fields Calculation Order.
Copy link to clipboard
Copied
Yep, that's what I found. It works now. Thank you
Copy link to clipboard
Copied
Not true. If you divide by a constant non-zero value it should work.
Copy link to clipboard
Copied
How would you get the calculation to round to the nearest hundreth?
Copy link to clipboard
Copied
Change this line:
event.value = (v1+v2)/2;
To:
event.value = ((v1+v2)/2).toFixed(2);
Copy link to clipboard
Copied
To round to the nearest hundredth, you need to use like this:
event.value = Math.round(((v1+v2)/2)/100)*100;
Copy link to clipboard
Copied
No script required, you can use the simplified notation:
(JJPC\ MCKTOTAL1 + JDPC\ MCKTOTAL1) * 0.5
The backslash is used to escape the space character.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now