Copy link to clipboard
Copied
Hello Adobe communty;
I need your help please. I have two text fields that a customer may enter value accoding to job requirement.
a. Total_EX_CFM b. TOTAL_EXHAUST
What my calcuation should do is if TOTAL_EXHAUST = 0 then value of Total_EX_CFM selected in the calculation. Here is my code:
// TOTAL Exhaust calculation script
// field name for dividend and divisor
var Total_EX_CFM = "Total_EX_CFM";
var TOTAL_EXHAUST = "TOTAL_EXHAUST"; // name for the total for row or column field - the dividend
var RM_VOLUME = "RM_VOLUME"; // name for the grand total for rows and columns - the divisor
// Get field values as numbers
var Total_EX_CFM = Number(this.getField(Total_EX_CFM).value);
var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);
var RM_VOLUME = Number(this.getField(RM_VOLUME).value);
(function () {
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}
else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}
else {event.value = "";} })();
Note: the if function works fine. The else if fuction isnot working. No error is diplaying in the console.
the code is under calculation --> custom calculation script:
Thank you.
Try this:
if (RM_VOLUME!== 0) {
if (TOTAL_EXHAUST == 0) event.value = Total_EX_CFM*60/ RM_VOLUME;
else event.value = TOTAL_EXHAUST*60/ RM_VOLUME;
}
else event.value = "";
You don't need this function stuff in the middle. Got rid of that line and the last one (in your first code) and it should work.
> You were missing "" in field names
No, that's not the issue. The field names were defined earlier in the code.
That would have caused a different kind of error message to appear, too.
Copy link to clipboard
Copied
Try this:
if (RM_VOLUME!== 0) {
if (TOTAL_EXHAUST == 0) event.value = Total_EX_CFM*60/ RM_VOLUME;
else event.value = TOTAL_EXHAUST*60/ RM_VOLUME;
}
else event.value = "";
Copy link to clipboard
Copied
Bernd;
Thank you for quick reply. I replaced your code after the if function. However, it is not working at all.
It displays "SyntaxError: missing } after function body
17:"
Thank you
Copy link to clipboard
Copied
Post your full code.
Copy link to clipboard
Copied
This is the current one:
// TOTAL Exhaust calculation script
// field name for dividend and divisor
var Total_EX_CFM = "Total_EX_CFM";
var TOTAL_EXHAUST = "TOTAL_EXHAUST"; // name for the total for row or column field - the dividend
var RM_VOLUME = "RM_VOLUME"; // name for the grand total for rows and columns - the divisor
// Get field values as numbers
var Total_EX_CFM = Number(this.getField(Total_EX_CFM).value);
var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);
var RM_VOLUME = Number(this.getField(RM_VOLUME).value);
(function () {
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {
if (TOTAL_EXHAUST == 0) event.value = Total_EX_CFM*60/ RM_VOLUME;
else event.value = TOTAL_EXHAUST*60/ RM_VOLUME;
}
else event.value = "";}
);
my orginal is;
// Get field values as numbers
var Total_EX_CFM = Number(this.getField(Total_EX_CFM).value);
var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);
var RM_VOLUME = Number(this.getField(RM_VOLUME).value);
(function () {
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}
else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}
else {event.value = "";} })();
Copy link to clipboard
Copied
You don't need this function stuff in the middle. Got rid of that line and the last one (in your first code) and it should work.
Copy link to clipboard
Copied
Do you mean like this? if so it is not working. Am I missing something?
// Get field values as numbers
var Total_EX_CFM = Number(this.getField(Total_EX_CFM).value);
var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);
var RM_VOLUME = Number(this.getField(RM_VOLUME).value);
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}
else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}
Thank you
Copy link to clipboard
Copied
Why doesn't you use my script?
Copy link to clipboard
Copied
I did. I replaced my if statement with yours as you see on my reply the code is displaying an error.
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {
if (TOTAL_EXHAUST == 0) event.value = Total_EX_CFM*60/ RM_VOLUME;
else event.value = TOTAL_EXHAUST*60/ RM_VOLUME;
}
else event.value = "";
Thank you.
Copy link to clipboard
Copied
This script doesn't gives a error message.
Copy link to clipboard
Copied
After debugging line by line. I finally found the issue now it work perfect. Thank you to you all.
Copy link to clipboard
Copied
You were missing "" in field names:
var Total_EX_CFM = Number(this.getField("Total_EX_CFM").value);
var TOTAL_EXHAUST = Number(this.getField("TOTAL_EXHAUST").value);
var RM_VOLUME = Number(this.getField("RM_VOLUME").value);
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}
else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}
Copy link to clipboard
Copied
> You were missing "" in field names
No, that's not the issue. The field names were defined earlier in the code.
That would have caused a different kind of error message to appear, too.
Copy link to clipboard
Copied
In his second post he only declared field names in his current code and not in his original code and in his 3rd post is his original code without "function" part and he is missing "" in that code so yes it is issue with that code.