I have been trying to create a dynamic PDF-XChange stamp with 4 dynamic text fields (Text1, Text2, Text3 and Text4) on the stamp that the user can edit in a dialog before the stamp is placed. What I want is for the user to select the stamp and the dialog popup to open with 4 user input fields:
- RMA Status - user to add the status (named RMAS)
- A free text field for the user to enter anything (named FREE)
- The user's name and business team, pulled from the user's Identity info (named TEAM)
- Today's date, editable incase they are stamping something after the fact (named DATE)
I had it working where it popped up a dialog box 4 times asking the user each question in a row, but a single dialog box with 4 text fields is what has been requested. I just can't seem to work out how my code below needs to change to work, but I'm very new to this.
Currently it only opens the last of the questions (date), unpopulated by my JavaScript date code just before dialog activation, none of the other questions. If I remove the date element, it asks the question before it (name and business unit), but it won't show a dialog with all 4 questions pre-populated using the data processed at the end of the code, which has been tested separately and is working.
My code is commented below. If anyone can help me to get the dialog to open with the 4 text fields pre-populated I would love to see where I went wrong. And if you can help me get it adding the data to the stamp's Text1 to Text4 boxes I'd be over the moon!
// 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);
Nailed it! In case anyone else wants to copy/paste this solution for themselves:
Hopefully someone will find this useful.