Copy link to clipboard
Copied
I have a simple excel IF formula below that I need help converting to java script. Any help would be greatly appreciated. Thank you!
=IF(G37>G39,G39,G37)
Copy link to clipboard
Copied
Have you looked a the MDN JavaScript Reference?
Do you have any experience with Object Programing?
There are two ways to program an If statement.
(logical statement) ? {block of code for true} : {block of code for false};
or
if(logical statement) {
// block of code for true;
} else {
// block of code for false;
}
Copy link to clipboard
Copied
I looked into the MDN JavaScript Reference but I had a hard time finding what I needed. I have no experience with object programming. I appreciate the help! Thank you!
Copy link to clipboard
Copied
The custom calculation script for the field could be:
(function () {
// Get the field values, as numbers
var G37 = +getField("G37").value;
var G39 = +getField("G39").value;
// Set this field's value
event.value = G37 > G39 ? G39 : G37;
})();
but replace "G37" and "G39" in the getField statements with the actual field names.
Copy link to clipboard
Copied
Below is what I have entered into the JavaScript editor. I'm still getting a Syntax Error. Can help me find out what I'm doing wrong?
(function () {
// Get the field values, as numbers
var Eligible for ReimbursementRow33.value = +getField("Eligible for ReimbursementRow33").value;
var Allowed.value = +getField("Allowed").value;
// Set this field's value
event.value = +getField("Eligible for ReimbursementRow33").value > +getField("Allowed").value? +getField("Allowed").value: +getField("Eligible for ReimbursementRow33").value;
})();
Copy link to clipboard
Copied
Variable names cannot have spaces in them. There are other problems too, but this should work:
(function () {
// Get the field values, as numbers
var Eligible_for_Reimbursement = +getField("Eligible for ReimbursementRow33").value;
var Allowed = +getField("Allowed").value;
// Set this field's value
event.value = Eligible_for_Reimbursement > Allowed ? Allowed : Eligible_for_Reimbursement;
})();
Copy link to clipboard
Copied
I have no errors pop up when I enter that java script in the custom calculation script. The only problem I do have is when I preview the report, the cell where I have the formula shows no value calculated. Is there something I am forgetting to do? Thank you for the help so far, I really appreciate it!
Copy link to clipboard
Copied
Try saving the document, closing Acrobat, and then open the document again. Confirm that the script is still there, and after changing some of the input fields, check the JavaScript console (Ctrl+J) for any errors.
Copy link to clipboard
Copied
This is what I get when I press Ctrl+J:
Acrobat EScript Built-in Functions Version 11.0
Acrobat SOAP 11.0
TypeError: getField("Eligible for ReimbursementRow33") is null
7:Field:Calculate
TypeError: getField("Eligible for ReimbursementRow33") is null
7:Field:Calculate
TypeError: getField("Eligible for ReimbursementRow33") is null
7:Field:Calculate
TypeError: getField("Eligible for ReimbursementRow33") is null
7:Field:Calculate
Copy link to clipboard
Copied
That means there's no such field with that name. You need to make sure you
enter it EXACTLY as it appears in the field's Properties window, including
upper/lower-case letters, spaces, etc.
Copy link to clipboard
Copied
Got it! Thank you for everything!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now