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

Find references to a deleted field

Explorer ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

Hi

I’m working on a PDF-Form that has about 150 fields. Many of these have calculations in it.

Some time ago someone deleted one or more fields but didn’t change calculations that refer to this field(s)…

If Acrobat comes across a calculation of this kind it only throws a general error “TypeError: this.getField(...) is null 1:Field:Calculate”. No information about the name of the field not found or  at least the name of the field that contains the invalid calculation …

Is there any easy way to find out which field is missing? Even if I’d take a look through the 2000 lines of JS-Code, it’s nearly impossible to keep the names of the 150 existing fields in mind, so you can tell: This name doesn’t exist …

Any help highly appreciated!

TOPICS
JavaScript , PDF forms

Views

1.1K

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 Expert , Jan 03, 2023 Jan 03, 2023

The missing field is:

TypeError: this.getField("GBestandt") is null
1:Field:Calculate

 

And the culprit calulator field is:

/*********** belongs to: AcroForm:Beitrag GBestandt:Calculate ***********/
if ((this.getField("Produkt").value== 1 )&&(this.getField("GBestandt").value>10000 )){this.getField("Beitrag GBestandt").value= (this.getField("GBestandt").value-10000)*0.66/1000 }
else {if ((this.getField("Produkt").value== 2 )&&(this.getField("GBestandt").value>10000 )){this.getField("Beitrag GBestand

...

Votes

Translate

Translate
Community Expert ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

Not an easy problem to solve, but it can be done.  

1) You'll need to get a list of all the fields referenced in the calculation scripts on the form. The easiest way to do this is to use the "Edit  all JavaScripts" option under the JavaScript tools. Copy all text and past it into a new text file.

2) Now you can write console window script to extract all the reference field names and compare them to the known field names.  

 

 

 

// First collect existing names
var oExistingFields = {};
for(var i=0;i<this.numFields;i++)
   oExistingFields[this.getNthFieldName(i)] = true;

// Now open text file and extract referenced names
var oStrm = util.readFileIntoStream();
var strFileText = util.stringFromStream(oStrm);
var rgGetFldRef = /getField\("([^"]+)"\)/mg;
var aMatch, aRefFields=[];
while(aMatch = rgGetFldRef.exec(strFileText))
  aRefFields.push(aMatch[1]);

// Now compare lists to find missing fields. 
var aMissing = [];
for(var i=0;i<aRefFields.length;i++)
{
    if(!oExistingFields[aRefFields[i]])
       aMissing.push(aRefFields[i]);
}

 

 

 

And now you have a list of fields that are referenced in all of the code on the form, but do not exist on the form. 

There are some issues with this method. 

1) The list of referenced fields does not filter for unique names, so there may be many repeats

2) Field names that are generated or stored in a variable are not included.

3) Fields that are referenced by a group name will be included in the missing,when they are not. 

 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

Thanks a lot @Thom Parker !

I am not a programmer and not very good at JS either. I must admit that I do not understand your code completely.

At the end of the week I'll be at our head office, a coworker from IT is quite familiar with JS - but he always stresses that he has no clue about PDFs 🙂

Will get back to you later.

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 ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

Older versions of Acrobat actually reported the name of the field in the error message. Some genius apparently decided this information was not needed and replaced it with an ellipsis in Acrobat DC...

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
Explorer ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

OT!

That's one thing, that's always puzzling me. I started getting into all this computer stuff in the mid 80’s. I had a Word Processor-Spreadsheet-Database-Program called SmartWare from Informix, later Angoss, later SmartWare Corp.

 

Unfortunately, the owners didn't manage to lift the program from DOS into the Windows-World. It became more and more outdated and was eventually discontinued at the beginning of the new century.

 

But if I think back, I always realize that there were things they did better - nearly 40 years ago! I'd expect programmers to take the best from older programs - add something new - and end up with a better product in every way. But the that's not the way the market does work 😞

 

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 ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

Yes and no.
Now it doesn't give the names of the fields concerned but since Acrobat DC it indicates the number of the script line that causes the error, it also indicates where the script is located.
This was not the case in the previous versions, so it can be considered as an improvement because it's often more useful than just knowing the name of the faulty 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
Explorer ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

quote

...but since Acrobat DC it indicates the number of the script line that causes the error, it also indicates where the script is located. ...


By @JR Boulay

 

Okay, that would be great, but unfortunately, I can't see ... maybe I'm looking up the wrong tree?

 

Here is what I do:

  1. I activate "Preferences > JavaScript > Show console on ...
  2. Open the PDF-Form and start input.
  3. When I activate the Checkbox "Produktlinie" the "JavaScript Debugger" pops up and shows me a message:

TypeError: this.getField(...) is null

1:Field:Calculate

 

Unfortunately, the "Produktlinie" is used in many of the calculations. And funny enough - in this form - the calculation does work. So - unlike the other form we discussed - the error doesn't mess up the whole calculation. I just would like to find out which field(s) are causing the trouble and also find a way to identify these fields easily - since I guess I will have to work on some more of these forms.

I'll send you the PDF and trust that you keep it confidentially.

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 ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

It has nothing to do with the check-box itself, per se. This code is under a Calculate script, most likely of a text field. When you change the value of any field in the file it triggers all calculation scripts, including the one that has this error.

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 ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

I have an old Mac running Acrobat 9 Pro and Acrobat XI Pro, it's the last version that gives the missing field's name in the error messages.

You can share your document here or send it privatly if you want me to test it and get the name of the concerned fields.

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 ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

Acrobat XI did it too.

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 ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

I didn't know that.
I have corrected my previous posts.
Thank you.

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 ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

Ok JR, what are we missing? I didn't see the form posted. And what didn't you know?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

@Thom Parker 

I sent the form to JR by PN. Though it is not "Top Secrect" it should not be spread in public.

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 ,
Jan 04, 2023 Jan 04, 2023

Copy link to clipboard

Copied

quote

@Thom Parker 

I sent the form to JR by PN. Though it is not "Top Secrect" it should not be spread in public.


By @GGN


 

No worries, I was just starting to think JR was a psychic debugger. Pretty impressive 😉

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jan 04, 2023 Jan 04, 2023

Copy link to clipboard

Copied

Thom Parker: I didn't know that Acrobat XI did it too.

I thought this change in the console messages was since Acrobat X, but try67 is right: it is from Acrobat DC.

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 ,
Jan 04, 2023 Jan 04, 2023

Copy link to clipboard

Copied

LATEST
quote

Thom Parker: I didn't know that Acrobat XI did it too.

I thought this change in the console messages was since Acrobat X, but try67 is right: it is from Acrobat DC.


By @JR Boulay

 

You know the current DC is 10 major versions past the first one. I think there have been several changes in error reporting since DC was first released. Since the name doesn't change, it is hard to tell when it actually happened. 

 

But regardless, you have to wonder why someone thought reporting less information would be helpful. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

The missing field is:

TypeError: this.getField("GBestandt") is null
1:Field:Calculate

 

And the culprit calulator field is:

/*********** belongs to: AcroForm:Beitrag GBestandt:Calculate ***********/
if ((this.getField("Produkt").value== 1 )&&(this.getField("GBestandt").value>10000 )){this.getField("Beitrag GBestandt").value= (this.getField("GBestandt").value-10000)*0.66/1000 }
else {if ((this.getField("Produkt").value== 2 )&&(this.getField("GBestandt").value>10000 )){this.getField("Beitrag GBestandt").value= (this.getField("GBestandt").value-10000)*0.87/1000 }
else {this.getField("Beitrag GBestandt").value=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
Explorer ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

Thank you very much JR! Now I got to find out what this field is / was good for ...

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