Skip to main content
TylerAtVCU
Participant
March 10, 2022
Answered

Questions on mirroring fields with custom calculations

  • March 10, 2022
  • 1 reply
  • 692 views

I'm trying to set up a form that is going to generate an expiration time based on a date and time entered in a form. In this instance, the date entered as the production date will create a date in the expired date field to be 1 day later but all I need to do for the time field is mirror it. I seem to be doing something wrong though and I'm not sure what:

 

I've got the production time field, titled as prodTime and I've got the expiration field labeled as expiredTime. I've got the custom calculation script set up to use event.value=this.getField("prodTime").valueAsString; which is what multiple threads I've been able to find suggest is the proper code for mirroring a field somewhere else on the form. In my case, I'm just getting a blank field. Any idea on what I'm doing wrong?

This topic has been closed for replies.
Correct answer try67

That means you entered an incorrect field name as the parameter for getField. Keep in mind that JS is case-sensitive, so if the field is called "ProdTime" and you wrote "prodTime", that won't work.

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
March 10, 2022

Look at the JavaScript console for errors. Also, calculation scripts are only executed when a field changes. How do you get the date into the first field? Is the user entering it? 

TylerAtVCU
Participant
March 10, 2022

Oooh I didn't know there was a debugging tool. It says:

TypeError: this.getField(...) is null
1:AcroForm:expiredTime:Calculate

 

Yes to your second question. The user is entering the date and time as two separate fields. I haven't done the date calculations yet but otherwise once they enter the time into prodTime they would press enter or tab/click out of the field which constitutes an update correct?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 10, 2022

That means you entered an incorrect field name as the parameter for getField. Keep in mind that JS is case-sensitive, so if the field is called "ProdTime" and you wrote "prodTime", that won't work.