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

Need help with error message pertaining to doc-level js

Contributor ,
Nov 02, 2023 Nov 02, 2023

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!

 

TOPICS
JavaScript
785
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 02, 2023 Nov 02, 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;

}

}

View solution in original post

Translate
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 ,
Nov 02, 2023 Nov 02, 2023

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

Translate
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
Contributor ,
Nov 03, 2023 Nov 03, 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!   

Translate
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 ,
Nov 02, 2023 Nov 02, 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;

}

}

Translate
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
Contributor ,
Nov 03, 2023 Nov 03, 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!!!

Translate
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 ,
Nov 03, 2023 Nov 03, 2023
LATEST

Where does you use the scripts?

Translate
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