• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Formula help: adding up mileage fields then multiplying by .58 cent reimbursement rate.

Community Beginner ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

It woked - then when I saved .pdf it was lost when I reopened it.  Then it would only work in some fields an not others.  Now it won't work at all.

// Get first field value, as a number

var v1 = +getField("MileagemilesRow1").value;

// Get second field value, as a number

var v2 = +getField("MileagemilesRow2").value;

// Get third field value, as a number

var v3 = +getField("MileagemilesRow3").value;

// Get fourth field value, as a number

var v4 = +getField("MileagemilesRow4").value;

// Get first field value, as a number

var v5 = +getField("MileagemilesRow5").value;

// Calculate and set this field's value to the result

event.value = .58 * (v1 + v5);

TOPICS
PDF forms

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jul 09, 2019 Jul 09, 2019

Thank you for all your help.  There was a duplicate formula in another cell (which I had inadvertently copied) that was causing the problem.  But you had easier formulas to use.  Thank you, again!!!

Votes

Translate

Translate
Community Expert ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

You can use the simplified field notation:

(MileagemilesRow1 + MileagemilesRow5) * 0.58

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Still can't get it to total?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Where is your problem?

(0.0 + 0.0) * 0.58 is 0.0

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Thank you for all your help.  There was a duplicate formula in another cell (which I had inadvertently copied) that was causing the problem.  But you had easier formulas to use.  Thank you, again!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

I am having a similar issue, what am i doing wrong? with how I have it configured, it does not calculate the field AUTO: Mileage 1.0. I have 100 entered so it should calculate to $28 (100 miles x 0.28) but the value is $100.

 

*screenshot is attached, i cannot get it to upload

 
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

The problem is most likely the special characters in your field's name. Rename it or use a calculation script, like this:

event.value = Number(this.getField("AUTO: Mileage 1.0").valueAsString) * 0.28;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

Well, that definitely fixed it (changing the name) but now the Total is calculating the number entered, not the number that field calculates to. 

 

expense report 2.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

Sorry, I don't follow what you mean... Where did you place the code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

sorry i wasn't more clear. i put the code in both simplified field notation & custom calculation script. In simplified, i enter 100 & it calculates to $28 but the total (calculates the sum of all fields in this section) calculates $100 (it is calculating the value entered (100), not the value calculated ($28).

 

Thanks for jumping in & helping so quick. I spent hours online & watching videos trying to get it to work. You have been the most helpful!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

It can't be in both places. Use it only under the third option: Custom Calculation Script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

sorry, i didn't finish typing that out! *doh

i tried it in both. in the custom field, it did not calculate at all (i entered 100 & it displayed $100).

 

the code i used is: Mileage * 0.28

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

Did you rename the field to "Mileage"? Check the JS Console (Ctrl+J) for error messages.

If it still doesn't work share the actual file with us.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

yes, i renamed it to Mileage & updated the code you shared above event.value = Number(this.getField("Mileage").valueAsString) * 0.28. i attempted to attached the file but it was flagged as spam. here is the error message in the JS Console:

TypeError: this.getField(...) is null
1:Field:Calculate
TypeError: this.getField(...) is null
1:Field:Calculate
TypeError: this.getField(...) is null
1:Field:Calculate
TypeError: f is null
1282:byteCodeTool
ReferenceError: Mileage is not defined
1:Field:Calculate
ReferenceError: Mileage is not defined
1:Field:Calculate
ReferenceError: Mileage is not defined
1:Field:Calculate
ReferenceError: Mileage is not defined
1:Field:Calculate
ReferenceError: Mileage is not defined
1:Field:Calculate
ReferenceError: Mileage is not defined
1:Field:Calculate

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

If you're using this:

Mileage * 0.28

It needs to go in the Simplified Field Notation option, not the Custom Script one...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

that is what i did & got the result i pasted above (enter 100 & it calculates to $28 but the Total calculates to $100, not $28)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

Are you calculating the value of the total field, or the Mileage field?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

both. calculating the mileage in the mileage field & total of all fields in the Auto category. (the mileage field is the 1st field in the Auto category).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

So what's the formula for each one?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

the formula for the mileage field is: Mileage * 0.28 in the Simplified field notation

the calculation in the TOTAL field is set to: Value is the sum (+) & all fields under Auto are selected.

 

Is there a way I can upload my document to you? This is my first created form using Adobe so I really appreciate your patience.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

That doesn't make sense. You can't use a field's own value in its calculation.

That's like using this formula:

x = x + 5

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2019 Oct 31, 2019

Copy link to clipboard

Copied

LATEST

ah!!!!! well that explains it...we were trying to avoid showing the mileage rate but I think i can add it to the form & use it in the calculation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines