Skip to main content
Participant
November 10, 2020
Answered

Calculated Field - User Entry

  • November 10, 2020
  • 2 replies
  • 730 views

We user Acrobat with merge functions from a database. We concatenate "City, State Postal Code" with a Custom calculation script. In some records, we have a 'Bad Address Flag', which leaves these data fields empty in the merge process.


Our users would like to type in a City State Postal Code into the Text Field. But, because the field has a formula using 'event.value = ***", the manually entered information gets over-written when the user tabs out of the field.

 

My question is : is there are different command than 'event.value' which will allow the retention of the manually entered information ... or ... is there a way to wrap my custom calucation script in an IF THEN logic that will take the merge data if it is available, or retain the manual info, if merge info is not available? 

 

Thanks, 

Mike

This topic has been closed for replies.
Correct answer try67

There is, but it's tricky. The way to do it is to look at the source of the calculation (via event.source.name). If it's one of the fields whose values you're combining ("City", "State", etc.) then proceed with the calculation. If not, do nothing. This will allow the user to enter a custom value, and won't overwrite it the next time the value of another field is changed.

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 10, 2020

There is, but it's tricky. The way to do it is to look at the source of the calculation (via event.source.name). If it's one of the fields whose values you're combining ("City", "State", etc.) then proceed with the calculation. If not, do nothing. This will allow the user to enter a custom value, and won't overwrite it the next time the value of another field is changed.

Participant
December 4, 2020

This pointed me in the right direction. I found a method that is successful just using an "if" statement against one of the field lengths.

 

if (getField("ADDRESS_CITY").value.length >2) event.value =

this.getField("ADDRESS_CITY").valueAsString +", "+
this.getField("ADDRESS_STATE").valueAsString +" "+

this.getField("ADDRESS_POSTAL_CODE").valueAsString;

 

I could see myself getting in trouble if there is a city named "OY' or something ... but for the moment, this works. If there is a city in the data, we extract 'City, State Postal Code'. If there is a bad address, the user can populate the data field with data manually.

Nesa Nurani
Community Expert
Community Expert
November 10, 2020

Don't know your exact code but try something like this if you want manually enter when field is empty:

if(event.value == ""){

event.rc = false;}

Participant
December 4, 2020

Thank you ... it was the 'if' statement.