Skip to main content
Inspiring
January 2, 2023
Answered

Find references to a deleted field

  • January 2, 2023
  • 4 replies
  • 2145 views

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!

This topic has been closed for replies.
Correct answer JR Boulay

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}

4 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
January 3, 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 GBestandt").value= (this.getField("GBestandt").value-10000)*0.87/1000 }
else {this.getField("Beitrag GBestandt").value=0}

Acrobate du PDF, InDesigner et Photoshopographe
GGNAuthor
Inspiring
January 4, 2023

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

JR Boulay
Community Expert
Community Expert
January 3, 2023

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.

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
January 3, 2023

Acrobat XI did it too.

GGNAuthor
Inspiring
January 4, 2023

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

 


@Thom Parker 

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

try67
Community Expert
Community Expert
January 2, 2023

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...

GGNAuthor
Inspiring
January 3, 2023

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 😞

 

JR Boulay
Community Expert
Community Expert
January 3, 2023

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.

Acrobate du PDF, InDesigner et Photoshopographe
Thom Parker
Community Expert
Community Expert
January 2, 2023

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
GGNAuthor
Inspiring
January 3, 2023

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.