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

Calculation stops working after saving and re-opening the file...

geophray
Registered: Jun 13 2008
Posts: 40

I am having the darndest time figuring out how to make this calculation work after i save the file, close it, and reopen it. It works flawlessly before i close and reopen the file, but then once I do, it stops working. I can get it to work again by simply opening the javascript editor and adding a space or taking one out, but i know i shouldn't have to do that every time the file is opened. Any ideas about what is going on?

My Product Information:
Acrobat Pro 8.1, Windows
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Make sure the field calculation order is correct.

George
geophray
Registered: Jun 13 2008
Posts: 40
I have tried to do that, but the field that does the calculation doesn't show up on the list of fields... Would it do that because it is a read only field?
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
It's not because it's read-only. Calculated fields should normally be set to read-only. It's not normal that the field doesn't show up when you attempt to set the field calculation order. As a test, I'd be inclined to delete the field, save the file, and then recreate the field. It sounds like something could be corrupted.

George
geophray
Registered: Jun 13 2008
Posts: 40
Another thing that is different about the field is that it is hidden until a certain value is chosen in another drop down list, and it then becomes visible. Would that have anything to do with it? Although, I have had this problem on another field as well... one that was always visible. I will try what you suggested... Thanks.
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
I assumed the calculations are performed in the field's Calculate event and that the fields were created in Acrobat, as opposed to Designer. Is that the case?

George
geophray
Registered: Jun 13 2008
Posts: 40
Yes. I have tried using the keystroke and custom format options too...
geophray
Registered: Jun 13 2008
Posts: 40
Does anybody else have any idea how to fix this?
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Can you post the code you're using in the custom calculation script?

George
geophray
Registered: Jun 13 2008
Posts: 40
This is one of the many instances, which leads me to believe there is something wrong with me... :)


if (this.getField("Loan_Amount").value > 1)
{
this.getField("Provident_YSP.1").value = ((this.getField("Provident_YSP.2").value/100)*this.getField("Loan_Amount").value);
}
else
{
this.getField("Provident_YSP.2").value = 0;
}


Thanks George...
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Almost there. What is the name of the field to which this script is attached?

George
geophray
Registered: Jun 13 2008
Posts: 40
it is "Provident_YSP.1", however, there is one named "Provident_YSP.2" that communicates with the former one and has a similar formula with the same problem... They are designed to auto-populate based on the other fields entry... (they are different than the original field i asked about in the very first posts that was read only...)
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
OK. The purpose of a calculation script is to set the value of the field to which it is attached, based on some criteria. To set the value of the field, you assign a value to the event.value property.

Your script is (incorrectly) attempting to set the value of the field to which it is attached, and also to set the value of a different field. You should not do this here, but rather in the other field's calculation script.

I would suggest changing the script above to something like:

if (getField("Loan_Amount").value > 1) {// Set the value of this field
event.value = getField("Provident_YSP.2").value/100 * getField("Loan_Amount").value;

} else {

// What do you want the value of this field to be in this case???

}

In the "else" case, you will have to figure out what the field value should be and set it there.

You will then need to clean up the script for "Provident_YSP.2". Instead of trying to set its value here, let its calculation script take care of it.

I suspect there will be other problems, but without knowing how the "Provident_YSP.2" field is supposed to work I can't be sure.

George
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Have you looked at the JavaScript Debugger Console for any error messages?

I have Acrobat and LiveCycle Designer open when I work with LCD and sometimes there are runtime errors there not caught by LCD when moving to the preview.

Since JavaScript and FormCalc are interpreted at run time, the run until an error occurs and then stopsdead and nothing following the error is processed, so checking the Debugging Console is very important. It will show the line and a cryptic hint as to what is wrong.

George Kaiser

geophray
Registered: Jun 13 2008
Posts: 40
George,

I apologize... that was a type-o. It should have read Provident_YSP.1 in the else section. At any rate, I changed it to the following and it is working ok. (There are a few differences because i started over from a blank form.)

if ( getField("Loan Amount").value > 1 ){//Set the value of this field
event.value = getField("Provident YSP.1").value/100*getField("Loan Amount").value;

} else {

//Set the value of this field
event.value = 0;
}

Now, however, every time the form is cleared, "Provident Funding" shows up in the lender field even though it is not the default value. I have played around a little bit and determined that it is because of another field (Provident Underwriting Fee) that I am trying to create. (It only does it when the javascript is present in the Provident Underwriting Fee field.) It is supposed to calculate 0.125% of the loan amount if Provident Funding is selected and 0 if any other option is selected. The following is what I have entered there...

if (getField("Lender").value = "Provident Funding"){

//Set the value of this field
event.value = getField("Loan Amount").value*0.00125;

} else {

//Set the value of this field
event.value = "0";
}

Also, i would like to have both Provident YSP fields able to be calculated from the other field, so that the user can enter a value in either field and the other one will automatically be calculated. Is there a way to do that?

Thanks so much for your help...
geophray
Registered: Jun 13 2008
Posts: 40
gkaiseril,

I have tried playing around with the debugger in acrobat and I'm sorry to say that i'm not quite sure how it works. It gave me the same error message about a couple hundred times in the same window... if that makes any sense. Also, i'm not using LCD...

Thanks!
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
That error message will point to the problem. It is repeated because Acrobat is recalculting each field with a calculation and crashing. If it is something about a missing property, you may have a misspelling somewhere.


Misspellers of the world untie!

George Kaiser

geophray
Registered: Jun 13 2008
Posts: 40
George and gkaiseril,

Thanks so much to both of you! I finally got the form working the way it is supposed to thanks to both of your input. I just have one last question... I am trying to make two fields basically read eachother... and auto populate/calculate based on what is entered in the opposite field. Is there a way to do that? I have the code in both of them to get the correct value, but since one of them has to come first in the calculation order, the one that is first always "wins"... Does that make sense?

Once again, I really appreciate all your help!
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Please explain in detail what you want to accomplish and include any code you're currently using, and where you've placed it.

George
geophray
Registered: Jun 13 2008
Posts: 40
Ok... I have two fields named Provident_YSP.1 and Provident_YSP.2. Here is what they are supposed to do and the code that is currently in their respective custom calculation fields:

Provident_YSP.1: Based on the dollar amount that is entered in Provident_YSP.2, it will calculate what that dollar amount is as a percentage of the loan amount.

if (getField("Loan_Amount").value > 1){//Set the value of this field
event.value = (getField("Provident_YSP.2").value/getField("Loan_Amount").value)*100;

} else {

//Set the value of this field
event.value = 0;


}


Provident_YSP.2: I want this field to take the percentage of the loan amount that is entered in Provident_YSP.1 and turn it into a dollar amount.

if ( getField("Loan_Amount").value > 1 ){//Set the value of this field
event.value = getField("Provident_YSP.1").value/100*getField("Loan_Amount").value;

} else {

//Set the value of this field
event.value = 0;
}


The idea is that i want to give the user the option of entering a value in either one of the two fields and having the other one auto populate.

Thanks!

-Jeff
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
I see. You should not be using calculation scripts, but rather set the value of the other field in the entry field's Validate event.

Calculated fields should be set to read-only and not used for data entry. What you're doing is setting up a circular reference that is bound to cause problems.

So, what should the Validate script then be? The Validate event of a text field gets triggered when the field value is committed (by the user pressing Enter or tabbing out of the field, for example) if the value is changed. The custom Validate script for Provident_YSP.1 might be something like:

var v1 = getField("Loan_Amount").value;
var f2 = getField("Provident_YSP.2");

if (v1 > 1) {// Set the value of Provident_YSP.2 based on value of this field;
f2.value = event.value/100 * v1;

} else {

//Set the value of Provident_YSP.2 to zero
f2.value = 0;

}


You would do something similar for the Validate script of Provident_YSP.2 to determine and set the value of Provident_YSP.1.

Let us know how it goes.

George
geophray
Registered: Jun 13 2008
Posts: 40
It's not liking this part...

// Set the value of Provident_YSP.2 based on value of this field;
f2.value = event.value/100 * v1;

It comes back with the error that "The value entered does not match the format of the field [ Provident_YSP.2 ]" In the debugger the value that comes back is NaN. Not sure what that means...
geophray
Registered: Jun 13 2008
Posts: 40
When i have what you suggested entered in both the respective validate boxes, it seems like the two scripts are fighting with eachother... it closes the pdf. And then upon re-opening it neither of them work... Any ideas?
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
D'oh! I just told you to set up a circular reference situation, which as I mentioned is going to cause problems. Sorry about that. Let's rethink this...

George