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

Dynamic Stamp with Dropdown - Value not output to field

Community Beginner ,
Feb 18, 2024 Feb 18, 2024

I've read through most of the dynamic stamp and dropdown articles.  I have my dropdown dialog working but it doesn't output the selected value to the text field the code is run from.  I made this from some code off the forum I modified.  This is my first attempt at something more than just text fields.

 

I'm sure I am missing something stupid.

 

var builder =
    {

    // This maps to a Popup Group in the PDF named 'Review'

    popupGroup: "Review Type",

    listItems:

    [
        {
            popl:
            {

                //list of items of Popup menu, positive number indicates default selection

                "REVIEWED": -1,

                "REVIEWED AS NOTED": -1,

                "REVISE AND RESUBMIT": -1,

                "REJECTED": -1,

                "FOR INFORMATION ONLY": -1

            }

        }

    ],

}
if (event.source.forReal)
    {

    var stampDialog = CreateDialog(builder);

    app.execDialog(stampDialog);

    this.getField(builder.popupGroup).value = stampDialog.popupSelection;

}

function CreateDialog(dialogBuilder)
{

    var sd = new Object();

    sd.builder = dialogBuilder;

    sd.popupSelection = "";

    var popupElements = new Array();

    popupElements[0] =
        {

        type: "popup",

        item_id: "popl",

        field: sd.builder.popupGroup,

        width: 250

    };

    var popupCluster =
        {

        type: "cluster",

        name: builder.popupGroup,

        elements: popupElements

    };

    sd.initialize = function (dialog)
    {

        var init = new Object();

        dialog.load(init);

        dialog.load(this.builder.listItems[0]);

    };

    sd.commit = function (dialog)
    {

        var res = dialog.store();

        for (var i in res["popl"])

            if (res["popl"] > 0)
                {

                this.popupSelection = i;

            }

    };

    sd.description =
        {

        name: "Stamp Dialog",

        elements:

        [
            {

                type: "view",

                align_children: "align_fill",

                elements:

                [

                    popupCluster

                ]

            },
            {

                type: "ok"

            }

        ]

    };

    return sd;

}

 

 

TOPICS
JavaScript , PDF , PDF forms
985
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 ,
Feb 18, 2024 Feb 18, 2024

This code is from a BlueBeam example stamp.  I find the CreateDialog function massively over complex, why not just write out the actual dialog code. It is so much simpler and straight forward. 

If you really want to go down this road, then you'll need to do some debug.

 

1. Are any errors reported in the console window?

2. Have you validated the value of  "stampDialog.popupSelection"?

3. Is the target field on the stamp named "Review Type"

 

 

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

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 Beginner ,
Feb 18, 2024 Feb 18, 2024

I only have Acrobat Standard so I don't have full console.  Trying to get the company I work for to upgrade but this is a step to get there.  I need them to see the value in a better stamp.

 

Do I need to validate it as I am just passing the text in to the field?

 

Yes the field in the stamp is "Review Type"

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 Beginner ,
Feb 18, 2024 Feb 18, 2024

Also I'm not the greatest with Javascript

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 ,
Feb 18, 2024 Feb 18, 2024

Standard actually does include the debugger. You'll find a free tool here that will display it. 

https://www.pdfscripting.com/public/Free_Acrobat_Automation_Tools.cfm 

it's labeled as "Reader JavaScript Console Window" , but it works for Standard as well.

And here's a tutorial on using the console window:

https://www.pdfscripting.com/public/images/video/AcroJSIntro/AcroJSIntro_ConsoleWindow.cfm

 

 

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

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 Beginner ,
Feb 19, 2024 Feb 19, 2024

So I got the console enabled, the moment I try to apply the stamp I get the following error.

 


ReferenceError: popl is not defined
180:App:Calculate

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 ,
Feb 19, 2024 Feb 19, 2024

That's the problem, or at least one of them. I'd suggest finding that spot in the code.  However, there are not 180 lines in the script you posted. So there must be more code somewhere. 

 

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

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 Beginner ,
Feb 19, 2024 Feb 19, 2024

I've been stumped on that too, There isn't anything else, which is odd for line 180.

 

The other thing I've noticed is my console will show erros but I can't run any code.

 

If I try to get the stamp name

SelectedAnnots[0].AP

 

I get nothing back,  I know the stamp name from the Templates, but the console seems like it doesn't fully work.

 

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 ,
Feb 19, 2024 Feb 19, 2024

If you can type into the console, then it is working.  It is possible that the code in the console is not being properly executed. 

 

Given the wording of the error message, I'd say that "popl" is being used as a variable name somewhere in the calculation script.  

You should consider spending some time to learn JavaScript programming and the Acrobat JS model. These custom dialogs are amoung the most advanced, and most difficult to develop, features. 

 

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

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 Beginner ,
Feb 19, 2024 Feb 19, 2024
LATEST

I found some code that was a better base and just changed my stamp layout a bit.

 

I used the code from this link.
https://community.adobe.com/t5/acrobat-sdk-discussions/dynamic-stamp-with-multiple-input-from-option...

 

Everything is working now, thanks for all the help.

 

Last question is it possible to have multiline input or even have the text wrap in the field used for comments? 

Also is there a way if that field is multiline the enter key won't send the OK button but allow a new line?

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