Skip to main content
Participating Frequently
August 9, 2021
Answered

Javascript calculated field will not update, not calculation order error

  • August 9, 2021
  • 6 replies
  • 1683 views

I have created a PDF that uses a custom validation script to calculate the final score of an exam. I have gotten it to work a few times, then it stopped. There was no rhyme or reason why it stopped.

 

This is the script:

 

//variables
var bt = this.getField("BaseTotal").value;
var pm = this.getField("PenaltyMinutes").value;
var temp = 0;

//temp variable to store calc
temp = bt - pm;

//assign final value
event.value = temp;
 

I have verified that the calculation order is correct.

This topic has been closed for replies.
Correct answer Nesa Nurani

In field where you want to show result, go to calculate tab and put this inside simplified field notation:

BaseTotal-PenaltyMinutes

6 replies

LKL77Author
Participating Frequently
August 10, 2021

This is the file. I apologize for the mix up, it's the calculation script, not a validation script, that I'm having trouble with.

try67
Community Expert
Community Expert
August 10, 2021

There's an error in your code. Check the JS Console.

try67
Community Expert
Community Expert
August 9, 2021

Please share the file with us.

Bernd Alheit
Community Expert
Community Expert
August 9, 2021

Check the field calculation order. 

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
August 9, 2021

In field where you want to show result, go to calculate tab and put this inside simplified field notation:

BaseTotal-PenaltyMinutes

LKL77Author
Participating Frequently
August 10, 2021

Oh my! I was making this way more difficult than it needed to be! Thank you so much!

try67
Community Expert
Community Expert
August 10, 2021

That won't work, though, because there's no field in your file called "PenaltyMinutes".

JMFreeman
Inspiring
August 9, 2021

What field do you have this triggering for the calculation of? What do you mean about it stopping working? Is it providing a 0 every time or NaN? Do you have "Commit selected value immediately" enabled for the field that contains the custom calculation script?

Bernd Alheit
Community Expert
Community Expert
August 9, 2021

Use it as calculation script, not as validation. 

LKL77Author
Participating Frequently
August 9, 2021

I meant it is a calculation, not a validation.