Skip to main content
Participating Frequently
September 11, 2023
Answered

TypeError Redeclaration of const AcroForm

  • September 11, 2023
  • 1 reply
  • 1859 views

Good morning,
I have a problem here is my code:

 

const array1 = [
    [   
        "hdd", // Adresse Commanditaire
        "1 Rue de l\'ecole normale 81000 Albi", // Adresse Chaufferie
        false, // Contrat P3 Bool
        "D00WRCR", // Code D
        "ELM Leblanc megalie" // Information Chaudiere
        // Type chaudiere
        // Puissance chaudiere
        // Mode evacuation fumee
        // Annee chaudiere
        // classe 
        // Numero de serie
        // Information bruleur
        // Date mise en service bruleur
        // Numero de serie bruleur
        // Norme CE
        // Aspiration du local
    ],
    [   
        "INSPE", // Adresse Commanditaire
        "1 rue de la garene 81000 Albi", // Adresse Chaufferie
        false, // Contrat P3 Bool
        "D00WRCR", // Code D
        "Viessman ecodrift" // Information Chaudiere
        // Type chaudiere
        // Puissance chaudiere
        // Mode evacuation fumee
        // Annee chaudiere
        // classe 
        // Numero de serie
        // Information bruleur
        // Date mise en service bruleur
        // Numero de serie bruleur
        // Norme CE
        // Aspiration du local
    ]
];

var nomCom = this.getField("Nom Commanditaire");
var adresse = this.getField("Adresse de la chaufferie");

switch (nomCom.value){
    case 1 :
        adresse.value = array1[0][3];
        break;
    case 2 :
        adresse.value = array1[1][0];
        break;
    case 3 :
        // adresse.value = "1 rue de la garene 81000 Albi";
        break;
    case 4 :
        // adresse.value = "1 rue de la garene 81000 Albi";
        break;
    case 5 :
        // adresse.value = "1 Rue de l\'ecole normale 81000 Albi";
        break;
    case 6 :
        // adresse.value = "1 Rue de l\'ecole normale 81000 Albi";
        break;
        
}


This one was tested in the console of my browser and works very well, I have no errors. But in Acrobat it does. Moreover, when I try to access the 2nd table like array1[1][0], it sees nothing!
The error that appears in the console when I run the code is this:

TypeError: redeclaration of const array1
1:AcroForm:Nom Commanditaire:Calculate

 

Thanks for your help

Sincerely

This topic has been closed for replies.
Correct answer try67

Use var instead of const.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 11, 2023

Use var instead of const.

Participating Frequently
September 12, 2023

Thanks, but I don't understand why it does that! normally we can construct an array with blocked values.
thanks anyway

try67
Community Expert
Community Expert
September 12, 2023

You can use it, but only once. After you run the code one time, the constant object called "array1" is already defined, so your attempts of re-defining it fail, as it's not mutable. Using var is much easier, and there's no reason the values in the array will change, unless you do so yourself in your code.