Skip to main content
Inspiring
November 2, 2023
Answered

Need help with error message pertaining to doc-level js

  • November 2, 2023
  • 3 replies
  • 746 views

I keep getting this errror message

"TypeError: this.templates is null
4:Document-Level:myResetForm"

 

Here's the associated code

if (app.viewerType != "Reader") {
        for (var i = 0; i < this.templates.length; i++) {
            this.templates[i].hidden = true;
        }
    }
 
var spawnedPages = findSpawnedPages(this);
//console.println(spawnedPages.join(","))
for (var i=spawnedPages.length-1; i>=0; i--) {
this.deletePages(spawnedPages[i], spawnedPages[i]);
}
 
    var notReset = ["OwnerResidenceCounty", "RBOwnerResident", "RBOwnerCitizen", "RBOwnerHear", "OwnerName", "OwnerPhone", "OwnerEmail", "OwnerSex", "OwnerDOB", "OwnerID", "OwnerMailAddress", "OwnerMailCity", "OwnerMailState", "OwnerMailZip", "CkBxSamePhysicalAddress", "OwnerPhysicalAddress", "OwnerPhysicalCity", "OwnerPhysicalState", "OwnerPhysicalZip"];
    var resetFields = [];
    for (var i = 0; i < this.numFields; i++) {
        var fname = this.getNthFieldName(i);
        if (notReset.indexOf(fname) != -1)
            continue;
        resetFields.push(fname);
    }
    this.resetForm(resetFields);
....
Originally an Acroform I uploaded to Adobe Cloud Storage but have been editing/saving back and forth using Acrobat Desktop. Could this be a factor? Adobe Sign hasn't been used, just Cloud Storage. Thanks in advance!

 

This topic has been closed for replies.
Correct answer try67

There are no Templates in the file, so the templates property returns null. You need to account for that in your code, like this:

 

if (this.templates!=null) {

for (var i = 0; i < this.templates.length; i++) {

this.templates[i].hidden = true;

}

}

3 replies

Bernd Alheit
Community Expert
Community Expert
November 3, 2023

Where does you use the scripts?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 2, 2023

There are no Templates in the file, so the templates property returns null. You need to account for that in your code, like this:

 

if (this.templates!=null) {

for (var i = 0; i < this.templates.length; i++) {

this.templates[i].hidden = true;

}

}

Inspiring
November 3, 2023

Hi Try67! Yeah, it's perplexing because there are two functioning templates? Thank you Try67 for helping me! Very grateful for all you do here!! Thank you!!!

Bernd Alheit
Community Expert
Community Expert
November 2, 2023

You will get this error when the file has no template page.

Inspiring
November 3, 2023

Thank you Bernd for your response. So I know I originally had the file without templates, then added them. And the current file has templates. Adding these templates to a Cloud-saved file as a 'modification event to the Acroform' using the "Organize Pages" tool on the Acrobat desktop, while templates are present and functioning correctly, will continue to generate this error? I see Try67's fix below (amazing as usual!) but just seeking some education. Thanks in advance!