Javascript для динамического диалогового окна штампа PDF не работает

Я пытался создать динамический штамп PDF-XChange с 4 динамическими текстовыми полями (Text1, Text2, Text3 и Text4) на штампе, который пользователь может редактировать в диалоговом окне до размещения штампа. Я хочу, чтобы пользователь выбрал штамп и всплывающее диалоговое окно, чтобы открыть 4 поля ввода пользователя:

  1. Статус RMA - пользователь для добавления статуса (с именем RMAS)
  2. Свободное текстовое поле, в которое пользователь может ввести что угодно (названное БЕСПЛАТНО)
  3. Имя пользователя и бизнес-команда, взятые из идентификационной информации пользователя (с именем TEAM).
  4. Сегодняшняя дата, редактируемая, если они что-то штампуют постфактум (название ДАТА)

У меня это работало, когда 4 раза появлялось диалоговое окно, задающее пользователю каждый вопрос подряд, но было запрошено одно диалоговое окно с 4 текстовыми полями. Я просто не могу понять, как мой код ниже должен измениться, чтобы работать, но я очень новичок в этом.

В настоящее время он открывает только последний из вопросов (дата), не заполненный моим кодом даты JavaScript непосредственно перед активацией диалога, ни один из других вопросов. Если я удалю элемент даты, он задаст вопрос перед ним (имя и бизнес-подразделение), но не отобразит диалоговое окно со всеми 4 вопросами, предварительно заполненными с использованием данных, обработанных в конце кода, который был протестирован отдельно и работает.

Мой код прокомментирован ниже. Если кто-нибудь может помочь мне открыть диалоговое окно с предварительно заполненными 4 текстовыми полями, я хотел бы увидеть, где я ошибся. И если вы можете помочь мне добавить данные в поля Text1 to Text4 штампа, я был бы на седьмом небе от счастья!

// Dialog Definition 
var oDlg = {
    
    RMAStatus: "",
    FreeText: "",
    NameAndUnit: "",
    TodaysDate: "",

    description:
    {
        name: "Stamp details",
        elements:
        [
            {
                type: "view",
                elements:
                [
                    {
                        type: "view",
                        elements:
                        [
                            {
                                item_id: "lbl1",
                                type: "static_text",
                                name: "&RMA Stage",
                            },
                            {
                                width: 200,
                                height: 22,
                                type: "edit_text",
                                item_id: "rmas",
                            }
                        ],
                        type: "view",
                        elements:
                        [
                            {
                                item_id: "lbl1",
                                type: "static_text",
                                name: "&Free text field",
                            },
                            {
                                width: 200,
                                height: 88,
                                type: "edit_text",
                                item_id: "free",
                            }
                        ],
                        type: "view",
                        elements:
                        [
                            {
                                item_id: "lbl1",
                                type: "static_text",
                                name: "&Your name and team",
                            },
                            {
                                width: 200,
                                height: 22,
                                type: "edit_text",
                                item_id: "team",
                            }
                        ],
                        type: "view",
                        elements:
                        [
                            {
                                item_id: "lbl1",
                                type: "static_text",
                                name: "&Stamp date",
                            },
                            {
                                width: 200,
                                height: 22,
                                type: "edit_text",
                                item_id: "date",
                            }
                        ]
                    },
                    {
                        type: "ok_cancel",
                    }
                ]
            }
        ]
    },
    initialize: function(dialog) { // where the data in dialog elements is set when the dialog is first activated
        dialog.load({
            "rmas":this.RMAStage,  
            "free":this.FreeText,
            "team":this.CorrectName,
            "date":this.todaysDate,
        });
    },
    commit: function(dialog) { // where element data is acquired when the user presses the OK button
        var data = dialog.store();
        this.RMAStage = data["rmas"];
        this.FreeText = data["free"];
        this.CorrectName = data["team"];
        this.todaysDate = data["date"];
    }
};

/*
 * Pre-fill the dialog text fields with the data below
 */
/* RMA STAGE (for RMAS to be populated) */
oDlg.RMAStage = "RMA Stage";

/* FREE TEXT FIELD (for FREE to be populated)  */
oDlg.FreeText = "";

/* NAME AND UNIT (for TEAM to be populated)  */
var IdentityName, IdentityNameSplit, Unit;

/* Set Organisation Unit */
Unit = "Parks & Landscapes Team";  // Unlikely to change

/* Find correctly formatted username from Identity info */
if((identity.name != null) && !/^\s*$/.test(identity.name))
    IdentityName = identity.name;
else
    IdentityName = identity.loginName.replace(/\./g," ").replace(/\./g," ").replace(/\b(\w)/g,function(Word,cFst){return cFst.toUpperCase()});

if (IdentityName.indexOf(', ') > -1) { // If the result is "Surname, Firstname" swap the names to make "Firstname Surname"
    IdentityNameSplit = IdentityName.split(', ');
    oDlg.NameAndUnit = IdentityNameSplit[1] + " " + IdentityNameSplit[0] + ", " + Unit;
}
else
    oDlg.NameAndUnit = IdentityName + ", " + Unit;

/* FORMATTED DATE FIELD (for DATE to be populated)  */
var stampDate;
stampDate = new Date();
oDlg.TodaysDate = util.printd("dd mmmm, yyyy", stampDate);

// Start dialog function
app.execDialog (oDlg);

person Skry    schedule 04.05.2021    source источник


Ответы (1)


Успешно справился! Если кто-то еще захочет скопировать/вставить это решение для себя:

var pagDlg =
{

    result: "cancel",
    DoDialog: function () { return app.execDialog(this); },
    //definitions
    strDefFmt: "dd-mm-yyyy",
    strFmt: "dddd d mmmm, yyyy",
    vDate: new Date,
    strDate: "",
    iOChecked: false,
    abwChecked: false,
    //
    SetListSel: function (list, path) {
        if (path.length == 0) return;
        eval("list[\"" + ((path.join != "function") ? path : path.join("\"][\"")) + "\"] = 1");
    },
    GetListSel: function (oLstResult) {
        for (var item in oLstResult) {
            if ((typeof oLstResult[item] == "number") && (oLstResult[item] > 0))
                return item;
        }
        return "";
    },
    formatDate: function (d, f) {
        return util.printd(f, d);
    },
    //Initialize values that will be used in the pop-up dialogue
    initialize: function (dialog) {
        var unit = "Technical Services & Design";
        this.strDate = this.formatDate(this.vDate, this.strDefFmt);
        //this.strDate = this.formatDate(this.vDate, "dd mmmm, yyyy");
        //
        var dlgInit =
        {
            "date": this.strDate,
            "free": "Enter your description text here.", //enable this checkbox option as default
            "abw_2": IdentityName + ", " + unit,
            "rma": "RMA Stage",
        };
        dialog.load(dlgInit);
        iOChecked = dlgInit["free"]; // initialise and keep it the same as the value in dlgInit
        abwChecked = dlgInit["abw_2"];
        rmaChecked = dlgInit["rma"];
    },
    commit: function (dialog) { // Called when OK button is pressed
        var oRslt = dialog.store();
        var path = new Array();
        var d = oRslt["date"];  //OK Go date
        //
        if (typeof d == "string")
            d = util.scand(this.strDefFmt, d);
        if (d != null)
        {
            var cur = new Date;
            d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), cur.getHours(), cur.getMinutes(), cur.getSeconds());
        }
        this.vDate = d;
        //

        this.rmaChecked = oRslt["rma"];
        this.iOChecked = oRslt["free"];
        this.abwChecked = oRslt["abw_2"];
        this.strDate = oRslt["date"];
    },
    //Description of the layout of the Dialoge Window
    description:
    {
        name: "Stamp details",
        width: 450,
        elements:
        [
            {
                type: "view",
                width: 450,
                elements:
                [
                    {
                        type: "view",
                        align_children: "align_row",
                        elements:
                        [
                            {
                                item_id: "lbl1",
                                name: "RMA Stage",
                                type: "static_text",
                                width: 100,
                            },
                            {
                                item_id: "rma",
                                type: "edit_text",
                                width: 300,
                            },
                        ]
                    },
                    {
                        type: "view",
                        align_children: "align_row",
                        elements:
                        [
                            {
                                item_id: "lbl1",
                                name: "Free text",
                                type: "static_text",
                                width: 100,
                                alignment: "align_top",
                                align_children: "align_top",
                            },
                            {
                                item_id: "free",
                                type: "edit_text",
                                multiline: true,
                                width: 300,
                                height: 88,
                            },
                        ]
                    },
                    {
                        type: "view",
                        align_children: "align_row",
                        elements:
                        [
                            {
                                item_id: "lbl1",
                                name: "Name and team",
                                type: "static_text",
                                width: 100,
                            },
                            {
                                item_id: "abw_2",
                                type: "edit_text",
                                width: 300,
                            },
                        ]
                    },
                    {
                        type: "view",
                        align_children: "align_row",
                        elements:
                        [
                            {
                                item_id: "lbl1",
                                name: "Date",
                                type: "static_text",
                                width: 100,
                            },
                            {
                                item_id: "date",
                                type: "edit_text",
                                DateEdit: true,
                                width: 100,
                            }
                        ]

                    },
                    {
                        type: "ok_cancel",
                    },
                ]
            }
        ]
    }
};
/* NAME */
var IdentityName, IdentityNameSplit;

/* Find correctly formatted username from Identity info */
if((identity.name != null) && !/^\s*$/.test(identity.name))
    IdentityName = identity.name;
else
    IdentityName = identity.loginName.replace(/\./g," ").replace(/\./g," ").replace(/\b(\w)/g,function(Word,cFst){return cFst.toUpperCase()});

if (IdentityName.indexOf(', ') > -1) { // If the result is "Surname, Firstname" swap the names to make "Firstname Surname"
    IdentityNameSplit = IdentityName.split(', ');
    IdentityName = IdentityNameSplit[1] + " " + IdentityNameSplit[0];
}

if (event.source.forReal && (event.source.stampName == "#T2CKw07Lo6sr42d6F3ao#0"))
{
    if (pagDlg.DoDialog() == "ok")
    {
        var d = pagDlg.vDate; 

        this.getField("Text1").value = pagDlg.rmaChecked; // RMA Stage
        this.getField("Text2").value = pagDlg.iOChecked; // Free text
        this.getField("Text3").value = pagDlg.abwChecked; // Name and team
        this.getField("Text4").value = util.printd(pagDlg.strFmt, d); // Date
    }
    else
    {
        app.alert("Stamp cancelled", 3);
    }
}
else
{
    var d = pagDlg.vDate;
    event.value = util.printd(pagDlg.strFmt, d);
}

Надеюсь, кто-то найдет это полезным.

person Skry    schedule 27.05.2021