Skip to main content
Participating Frequently
October 22, 2024
Answered

PDF form with java script works in with adobe acrobat standard but not with acrobat reader / browser

  • October 22, 2024
  • 1 reply
  • 866 views

Hello,

 

I created a pdf form with a send button. This button has java script action and generates an email with a generative text depending from input and and option fields. The pdf works fine for me and another colleague who uses adobe acrobat standard. However the script is not working for colleagues who don't have an adobe acrobat standard license and just use the acrobat reader to open the file. Also when opening the pdf with a browser (chrome/edge) the script is not working.

Can you help me to get this working?

It took me a lot of time and I thought it will work in general, not just for me...

 

As @Thom Parker suggested I activated the java script debugging on the reader of a colleague, where the script is not working. Thanks a lot for that hint!

 

I get following Error Message:

 

NotAllowedError: Security settings prevent access to this property or method.
Doc.subject:54:Field button_versenden:Mouse Up

 

I am going to post the code in a reply to this post. The file is attached.

This topic has been closed for replies.
Correct answer PDF Automation Station

Certain words should not be used as variables because they already mean something in JavaScript.  subject is one such word because documents have a subject property.  Change the variable name 'subject' to something else. It is throwing a Security Error for subject in Reader because you can't write this property  Standard was writing the property then pulling the property value into the email subject.  The subject property should be accessible in Reader.  With a web browser, all bets are off when it comes to which scripts will function.

1 reply

Participating Frequently
October 22, 2024
// Flags für die Validierung
var hasProdNr = false; // Prüfen, ob mindestens eines der ProdNr-Felder befüllt ist
var hasFrgD = true;
var hasFrgDnoProdNr = true;
// Prüfen, ob mindestens eine Checkbox angekreuzt ist
var hasGewerk = this.getField("checkbox_karobau").value == "Ja" || 
                this.getField("checkbox_lack").value == "Ja" || 
                this.getField("checkbox_montage").value == "Ja";
// Prüfen, ob mindestens eine Sperrkategorie-Option ausgewählt ist
var hasSperrkategorie = true;
    if (this.getField("sperrkategorie").value == "Off") {
        hasSperrkategorie = false;
    }
var hasSperrgrund = this.getField("sperrgrund").value !== ""; // Prüfen, ob ein Sperrgrund eingetragen ist
var hasAbt = this.getField("abt").value !== ""; // Prüfen, ob Abteilung eingetragen ist
var hasDatum = this.getField("datum").value !== ""; // Prüfen, ob Datum eingetragen ist
var hasName = this.getField("name").value !== ""; // Prüfen, ob Name eingetragen ist
// Prüfen, ob mindestens eine Regress-Option ausgewählt ist
var hasRegress = true;
    if (this.getField("regress").value == "Off") {
        hasRegress = false;
    }




// Empfänger
var recipients = [];
if (this.getField("checkbox_karobau").value == "Ja" || this.getField("checkbox_lack").value == "Ja") {
    recipients.push("email1@google.com");
}
if (this.getField("checkbox_montage").value == "Ja") {
    recipients.push("email2@google.com");
}

// Betreff
var subjectParts = [];
if (this.getField("checkbox_karobau").value == "Ja") {
    subjectParts.push("Karosseriebau (MP 0.V)");
}
if (this.getField("checkbox_lack").value == "Ja") {
    subjectParts.push("Lackiererei (MP 1.1)");
}
if (this.getField("checkbox_montage").value == "Ja") {
    subjectParts.push("Montage (MP 2.09)");
}






// Betreff zusammenstellen
var subject = "Sperrung vor Einlauf in " + subjectParts.join(", ");







// E-Mail Text generieren
var body ="";


body += "Sperrung vor Einlauf folgender Gewerke:\n";
subjectParts.forEach(function(part) {
    body += "- " + part + "\n"; // Jedes Element mit "- " auflisten
});
body += "\n";

body += "Sperrkategorie:\t" + this.getField("sperrkategorie").value  + "\n\n";

body += "Sperrgrund:\n" + this.getField("sperrgrund").value  + "\n\n";

body += "Regressmöglichkeit:\t" + this.getField("regress").value  + "\n\n\n"

body += "Folgende Sperrungen müssen durchgeführt werden:\n\n";
body += "-----------------------------------------------------------------------------------------\n";
body += "|\t\t\tProdNr.\t\tVoraussichtl. Freigabe\t|\n";  //Spaltenüberschrift
body += "-----------------------------------------------------------------------------------------\n";
body += "|\t\t\t\t\t\t\t\t\t\t|\n"



// Liste der Input-Feldnamen
var inputFields = [];
for (var i = 1; i <= 18; i++) {
    var prodNrField = (i < 10 ? "ProdNr_0" : "ProdNr_") + i; // Füge führende Null für 01-09 hinzu
    var frgDField = (i < 10 ? "Frg_D_0" : "Frg_D_") + i; // Füge führende Null für 01-09 hinzu
    var frgZField = (i < 10 ? "Frg_Z_0" : "Frg_Z_") + i; // Füge führende Null für 01-09 hinzu
    inputFields.push({ prodNrField: prodNrField, frgDField: frgDField , frgZField : frgZField });
}

var hasValues = false; // Flag, um zu überprüfen, ob es Eingabewerte gibt

// Einfügen der Liste
inputFields.forEach(function(fields) {
    var prodNrValue = this.getField(fields.prodNrField).value; // Wert für ProdNr abrufen
    var frgDValue = this.getField(fields.frgDField).value; // Wert für Frg_D abrufen
    var frgZValue = this.getField(fields.frgZField).value; // Wert für Frg_Z abrufen

    // Überprüfen, ob mindestens eine ProdNr eingegeben wurde
    if (prodNrValue !== "") {
        hasProdNr = true; // Setze das Flag, wenn ProdNr nicht leer ist
    }

    // Überprüfen, ob ProdNr. leer, wenn Frg_D-Feld nicht leer ist
    if (frgDValue !== "" && prodNrValue ==="") {
        hasFrgDnoProdNr = false; // Setze das Flag, wenn ProdNr nicht leer ist
    }

    // Überprüfen, ob das Frg_D-Feld nicht leer ist, wenn ProdNr nicht leer ist
    if (prodNrValue !== "" && frgDValue === "") {
        hasFrgD = false; // Setze das Flag auf ungültig
    }


    // Überprüfen, ob das Frg_D-Feld ein Datum enthält und Frg_Z leer ist
    if (frgDValue !== "" && frgZValue === "") {
        frgZValue = "10:00"; // Setze auf "10:00"
        this.getField(fields.frgZField).value = frgZValue;
    }

    
    // Manuelle Formatierung der Zeile
    if (prodNrValue || frgDValue) { // Überprüfen, ob einer der Werte nicht leer ist
        hasValues = true; // Setze das Flag
        body += "| " + fields.prodNrField + "\t\t" + prodNrValue + "\t\t" + frgDValue + "\t" + frgZValue + " Uhr\t|\n";
        body += "|\t\t\t\t\t\t\t\t\t\t|\n"
    }
}, this);

body += "-----------------------------------------------------------------------------------------\n";









// E-Mail mit Anhang senden, nur wenn alle Eingaben gültig sind
if (hasProdNr && hasGewerk && hasSperrkategorie && hasSperrgrund && hasAbt && hasDatum && hasName && hasFrgD && hasFrgDnoProdNr && hasRegress) {

    //E-Mail generieren
    this.mailDoc({
        bUI: true,
        cTo: recipients.join("; "),
        cSubject: subject,
        cMsg: body
    });
} else {
    var errorMessage = "Bitte überprüfen Sie folgende Punkte:\n";
    if (!hasProdNr) errorMessage += "- Mindestens eine ProdNr. muss eingetragen werden\n";
    if (!hasFrgD) errorMessage += "- Für jede ProdNr. muss ein voraussichtl. Freigabedatum angegeben werden\n";
    if (!hasFrgDnoProdNr) errorMessage += "- Achtung: Es wurde ein Freigabedatum eingetragen aber keine dazugehörige ProdNr.\n";
    if (!hasGewerk) errorMessage += "- Sperrung vor Gewerk fehlt\n";
    if (!hasSperrkategorie) errorMessage += "- Sperrkategorie fehlt\n";
    if (!hasSperrgrund) errorMessage += "- Sperrgrund fehlt\n";
    if (!hasRegress) errorMessage += "- Bitte ankreuzen, ob eine Regressforderung möglich ist\n";
    if (!hasAbt) errorMessage += "- Abteilungskürzel fehlt\n";
    if (!hasDatum) errorMessage += "- Datum fehlt\n";
    if (!hasName) errorMessage += "- Ihr Namen fehlt\n";

    app.alert(errorMessage);
}
PDF Automation Station
Community Expert
Community Expert
October 22, 2024

Certain words should not be used as variables because they already mean something in JavaScript.  subject is one such word because documents have a subject property.  Change the variable name 'subject' to something else. It is throwing a Security Error for subject in Reader because you can't write this property  Standard was writing the property then pulling the property value into the email subject.  The subject property should be accessible in Reader.  With a web browser, all bets are off when it comes to which scripts will function.

Thom Parker
Community Expert
Community Expert
October 22, 2024

"subject" is a built-in document property. This is what it's complaining about.  Change it to a different name. 

 

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