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

Dynamic Stamps - Text Return as "Undefined". Why?

Community Expert ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

Hello...
I have a dynamic stamp with 4 checkboxes and 3 text fields plus a auto date field. The 4 check boxes and the date work well when I apply the stamp in a document. On the other hand, for the content of the text fields, the text returned by the dialog window returns nothing other than “undefined”. I can’t see what’s wrong... I need your advice before I hit my head on the computer! Thanks!

Below are my calculation script for the stamps in a separated field.

function Stamps() {
    var oJSDlg = {
        bChk1: null,
        bChk2: null,
        bChk3: null,
        bChk4: null,
        text1: "",
        text2: "",
        text3: "",
        initialize: function (dialog) {
            var oInit = {
                Chk1: this.bChk1,
                Chk2: this.bChk2,
                Chk3: this.bChk3,
                Chk4: this.bChk4,
                Text1: this.text1,
                Text2: this.text2,
                Text3: this.text3,
            };
            dialog.load(oInit);
        },
        validate: function (dialog) {
            var bRtn = true;
            var oRslt = dialog.store();
            return bRtn;
        },
        commit: function (dialog) {
            var oRslt = dialog.store();
            this.bChk1 = oRslt.Chk1;
            this.bChk2 = oRslt.Chk2;
            this.bChk3 = oRslt.Chk3;
            this.bChk4 = oRslt.Chk4;
            this.text1 = oRslt.Text1;
            this.text2 = oRslt.Text2;
            this.text3 = oRslt.Text3;
        },
        description: {
            name: "Conformité",
            elements: [{
                type: "view",
                width: 362,
                height: 200,
                elements: [
                    {
                        type: "check_box",
                        item_id: "Chk1",
                        name: "Vu",
                    },
                    {
                        type: "check_box",
                        item_id: "Chk2",
                        name: "Vu avec annotation(s)",
                    },
                    {
                        type: "check_box",
                        item_id: "Chk3",
                        name: "Corriger tel qu’annoté",
                    },
                    {
                        type: "check_box",
                        item_id: "Chk4",
                        name: "Refusé",
                    },
                    {
                        type: "edit_text",
                        item_id: "Text1",
                        width: 300,
                        height: 20,
                        name: "Text Field 1",
                    },
                    {
                        type: "static_text",
                        item_id: "Desc1",
                        name: "Description for Text Field 1",
                    },
                    {
                        type: "edit_text",
                        item_id: "Text2",
                        width: 300,
                        height: 20,
                        name: "Text Field 2",
                    },
                    {
                        type: "static_text",
                        item_id: "Desc2",
                        name: "Description for Text Field 2",
                    },
                    {
                        type: "edit_text",
                        item_id: "Text3",
                        width: 300,
                        height: 20,
                        name: "Text Field 3",
                    },
                    {
                        type: "static_text",
                        item_id: "Desc3",
                        name: "Description for Text Field 3",
                    },
                    {
                        type: "ok",
                    },
                ],
            }],
        },
    };

    if (event.source.forReal && (event.source.stampName == "#VBC")) {
        if ("ok" == app.execDialog(oJSDlg)) {
            this.getField("Chk1").checkThisBox(0, oJSDlg.bChk1);
            this.getField("Chk2").checkThisBox(0, oJSDlg.bChk2);
            this.getField("Chk3").checkThisBox(0, oJSDlg.bChk3);
            this.getField("Chk4").checkThisBox(0, oJSDlg.bChk4);
            this.getField("Text1").value = oJSDlg.text1;
            this.getField("Text2").value = oJSDlg.text2;
            this.getField("Text3").value = oJSDlg.text3;
        }
    }
}

Stamps();

 

TOPICS
General troubleshooting , JavaScript , PDF

Views

447

Translate

Translate

Report

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 ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

The "item_id" in a dialog object must be 4 and only 4 characters long.

Otherwise that item cannot be referenced and returns undefined as a value. 

 

 

 

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

View solution in original post

Votes

Translate

Translate

Report

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 ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

The "item_id" in a dialog object must be 4 and only 4 characters long.

Otherwise that item cannot be referenced and returns undefined as a value. 

 

 

 

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

Votes

Translate

Translate

Report

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 ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

Thank you Thom!

 

I was way out in the left field.

Votes

Translate

Translate

Report

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 ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

LATEST

That was it! Good chance you are here! Thanks Thom!

Votes

Translate

Translate

Report

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 ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

Hi @Jean-Claude Tremblay ,

 

 

I believe that the ubderlying undefined issue is in this line:

 

if (event.source.forReal && (event.source.stampName == "#VBC"))

 

event.source.forReal is missing this part :

 

== "#VBC" 

 

(I may be wrong though).

 

If that is not the issue I would check that the name of the text field objects match the same name in your script, OR, check if they have any formatting that is not accepting text input.

 

 

 

 

 

 

 

Votes

Translate

Translate

Report

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