These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Document level Function not working

Duniagdra
Registered: Sep 24 2008
Posts: 140
Answered

A two part question.

Part One:
I've entered the following function in each of seven total fields that sum up the values of seven fields specific to each of them.

TotalSeven("AB1_Mod","AB1_Arm","AB1_Class","AB1_PROF","AB1_FEAT","AB1_ENH","AB1_Misc1")
The function's formula is as follows:

function TotalSeven(M1,M2,M3,M4,M5,M6,M7)
{
var Mod1 = Number(this.getField(M1).value);
var Mod2 = Number(this.getField(M2).value);
var Mod3 = Number(this.getField(M3).value);
var Mod4 = Number(this.getField(M4).value);
var Mod5 = Number(this.getField(M5).value);
var Mod6 = Number(this.getField(M6).value);
var Mod7 = Number(this.getField(M7).value);
var Score = Mod1+Mod2+Mod3+Mod4+Mod5+Mod16+Mod7;
event.value  = Score;
}

I thought I was clever and took an idea and replicated it's principle, but none of my Total fields are totaling. What did I do wrong?

Part Two:
I have other Total fields that have fewer then seven values to total and some total groups have a set of values that fluctuate from 3 to 4. is there a way that, once I get the above function formula to work, that it can work on all my total fields regardless the number of field values available to total?

Example:

TotalSeven("AB1_Mod","AB1_Arm","AB1_Class","AB1_PROF","AB1_FEAT","AB1_ENH","AB1_Misc1")

OR

TotalSeven("AB1_Mod","AB1_Arm","AB1_Class","AB1_PROF")

Thanks in advance,
Jim.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

My Product Information:
Acrobat Pro 8.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
TotalSeven("AB1_Mod","AB1_Arm","AB1_Class","AB1_PROF","AB1_FEAT","AB1_ENH","AB1_Misc1")
What field event did you place this code in?

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
George_Johnson wrote:
TotalSeven("AB1_Mod","AB1_Arm","AB1_Class","AB1_PROF","AB1_FEAT","AB1_ENH","AB1_Misc1")
What field event did you place this code in?

George
I'm not following? Field event? I don't think I set anything for other fields that have only a function done the same way and they work. I thought the event was handled in the document level function; event.value?

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You have to place that call to the function somewhere, and I'm asking where you placed it. It would make sense to place it as the custom calculation script for a field.

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
George_Johnson wrote:
You have to place that call to the function somewhere, and I'm asking where you placed it. It would make sense to place it as the custom calculation script for a field.George
Oh! Oh yeah. Man, sorry about that, just wasn't catching on. Yeah, I have it in the custom script for each field. No validation, format numbers, did nothing in actions, options is ALL unchecked, appearance is default, and general is Visible - 0 degrees - read only.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Is there any JavaScript Debugger/Console errror being displayed?

I got the following error uing your code:

Quote:
Document-Level:Total
Exception in line 1 of function top_level, script AcroForm:Total:Calculate

Mod16 is not defined
12:AcroForm:Total:Calculate
Looking at line 12 of the document level function shows the use of a variable "Mod16" which does not appear to be defined. I would guess you wnated to use "Mod6" here.

As a side note, I would return the computed value from the function to provide more flexability in the use of the function. This would allow one to assign the computed value to a variable in another computation.

Your custom calculation would then become:

event.value = TotalSeven("AB1_Mod", "AB1_Arm",  "AB1_Class", "AB1_PROF", "AB1_FEAT", "AB1_ENH", "AB1_Misc1")
A little white space also helps make code easier to read.

A more generalized version of summing field's using just the field names:

// document level funcitonfunction SumNames() {var sum =0; // clear the result// add the value for each passed named fieldsfor(i=0; i < arguments.length; i++) {sum += Number(this.getField(arguments[i]).value);}// return the computed sumreturn sum;} // end SumNames function

And the filed level custom calculation script would be:
event.value = SumNames("AB1_Mod", "AB1_Arm",  "AB1_Class", "AB1_PROF", "AB1_FEAT", "AB1_ENH", "AB1_Misc1")
And if you later needed to add more fields, just add the names to the parameter list.

George Kaiser

Duniagdra
Registered: Sep 24 2008
Posts: 140
gkaiseril wrote:
Is there any JavaScript Debugger/Console errror being displayed?I got the following error uing your code:

Quote:
Document-Level:Total
Exception in line 1 of function top_level, script AcroForm:Total:Calculate

Mod16 is not defined
12:AcroForm:Total:Calculate
Looking at line 12 of the document level function shows the use of a variable "Mod16" which does not appear to be defined. I would guess you wnated to use "Mod6" here.

As a side note, I would return the computed value from the function to provide more flexability in the use of the function. This would allow one to assign the computed value to a variable in another computation.

Your custom calculation would then become:

event.value = TotalSeven("AB1_Mod", "AB1_Arm",  "AB1_Class", "AB1_PROF", "AB1_FEAT", "AB1_ENH", "AB1_Misc1")
A little white space also helps make code easier to read.
Thanks, While I did find and fix this, it still didn't help. One "totaling" field would sum up, but the other "totaling" fields still would not.

gkaiseril wrote:
A more generalized version of summing field's using just the field names:
// document level funcitonfunction SumNames() {var sum =0; // clear the result// add the value for each passed named fieldsfor(i=0; i < arguments.length; i++) {sum += Number(this.getField(arguments[i]).value);}// return the computed sumreturn sum;} // end SumNames function

And the filed level custom calculation script would be:
event.value = SumNames("AB1_Mod", "AB1_Arm",  "AB1_Class", "AB1_PROF", "AB1_FEAT", "AB1_ENH", "AB1_Misc1")
And if you later needed to add more fields, just add the names to the parameter list.
I'm impressed. I gave this a try and found it does work with a varying number of fields to be summed by a "totaling" field. Thanks. However, (I hate how there always seems to be a "however") I'm again running into the same problem as before where other "totaling" fields are not totaling their respective fields to be totaled. I'm going to look at this some more in the morning and see if I can find anything. I'll try and respond around noon EST. Thanks.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
It sounds like the "Calculation Order" is not correct. So you may need to reorder theit calculation order.

George Kaiser

Duniagdra
Registered: Sep 24 2008
Posts: 140
gkaiseril wrote:
It sounds like the "Calculation Order" is not correct. So you may need to reorder theit calculation order.
In regards to the calculation order, how do I know what order it should be in.

Example:

I have six fields the user fills in:

Strength
Constitution
Dexterity
Intelligence
Wisdom
Charisma

I then have a pair of six fields that are triggered by the above and work great. No delay, no having to enter values in other fields for them to react.

I then have these "total" fields for AC, Fortitude, Reflex, and Will that total up the values in their corresponding fields. Of each, there are two fields that are reactive off other inputs. One is reactive off a field named ECL and the other gets its input from the above results. Following these are a set of other fields that are currently user defined.

Do I set the calc order for these total fields after all fields needing input or will having them before all still allow them to pick up new values?

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You have to have any referenced calculated field computed before the calculated value can be used.

George Kaiser

Duniagdra
Registered: Sep 24 2008
Posts: 140
gkaiseril wrote:
You have to have any referenced calculated field computed before the calculated value can be used.
I did try messing around with the calc order, but it still does not calculate for Fort, Ref, and Will. I've looked into all fields to see if I missed something (spelling, "", something), but I'm just not seeing it. :(

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

Duniagdra
Registered: Sep 24 2008
Posts: 140
Well... I'm really having a hard time here. I've applied the above function "SumNames" to other "Totaling" fields and it works fine. It works great actually. I'm still stuck with this same three; Fortitude, Reflex, and Will totals that just won't pick up on their corresponding fields to be summed.

I'm at a loss as to what I'm missing.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
It's really hard to tell what's going on without seeing the file in question. Just yesterday someone sent me a file that was not calculating at it should. Upon removing and respecifying the Calculate actions for the fields, it started working as you'd expect. I don't know the cause of this type of behavior, but it's worth a try...

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
LOL

It's all so simple... I'm an ass...

I went line-by-line, character-by-character, and then had a friend clueless in anything computer other than turning it on and you can browse the web. Sure enough, I had some typo's; lower case when needing upper case, name inconsistency, and one " missing. To the both of you who tried helping me in this, I thank you for your time and patience. While I was displaying the code correctly here, it was incorrect in the document. another step complete.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You can open the JavaScript cosole/debugger and as a PDF form is updated for entries you will be able to see the errors. The message is confusing, but it does include the event triggering the problem, the line number, the object, and a very brief statment about the error.

See [url=http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/javascript_console/]The Acrobat JavaScript Console (Your best friend for developing Acrobat JavaScript)[/url] for more information.

One can even use JavaScripts "try{ }catch(){ }finally{}" method to trap errors and display the information a little more clearly.
try {// suspected problem codeapp.alert(); // one argument is required for alert} catch(e) {console.show(); // open console//caught error processingconsole.println("\nIndividual properties of the error:");for (var i in e) {console.println( i + ": " + e[i]); // individual properties of the error} // end catch processing } // end tryfinally {// statements to run after errorconsole.show();console.println("\nend of processing");} // end finally

George Kaiser

Duniagdra
Registered: Sep 24 2008
Posts: 140
Thanks. Being more careful in the beginning may help also. lol

I'll give this code a try though and will use debugger more frequently.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack