title: Javascript for a dynamic PDF stamp dialog box not working
body: <p>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:</p>
  <ol>
  <li>RMA Status - user to add the status (named RMAS)</li>
  <li>A free text field for the user to enter anything (named FREE)</li>
  <li>The user's name and business team, pulled from the user's Identity info (named TEAM)</li>
  <li>Today's date, editable incase they are stamping something after the fact (named DATE)</li>
  </ol>
  <p>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.</p>
  <p>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.</p>
  <p>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!</p>
  <pre><code>// Dialog Definition 
  var oDlg = {
      
      RMAStatus: &quot;&quot;,
      FreeText: &quot;&quot;,
      NameAndUnit: &quot;&quot;,
      TodaysDate: &quot;&quot;,
  
      description:
      {
          name: &quot;Stamp details&quot;,
          elements:
          [
              {
                  type: &quot;view&quot;,
                  elements:
                  [
                      {
                          type: &quot;view&quot;,
                          elements:
                          [
                              {
                                  item_id: &quot;lbl1&quot;,
                                  type: &quot;static_text&quot;,
                                  name: &quot;&amp;RMA Stage&quot;,
                              },
                              {
                                  width: 200,
                                  height: 22,
                                  type: &quot;edit_text&quot;,
                                  item_id: &quot;rmas&quot;,
                              }
                          ],
                          type: &quot;view&quot;,
                          elements:
                          [
                              {
                                  item_id: &quot;lbl1&quot;,
                                  type: &quot;static_text&quot;,
                                  name: &quot;&amp;Free text field&quot;,
                              },
                              {
                                  width: 200,
                                  height: 88,
                                  type: &quot;edit_text&quot;,
                                  item_id: &quot;free&quot;,
                              }
                          ],
                          type: &quot;view&quot;,
                          elements:
                          [
                              {
                                  item_id: &quot;lbl1&quot;,
                                  type: &quot;static_text&quot;,
                                  name: &quot;&amp;Your name and team&quot;,
                              },
                              {
                                  width: 200,
                                  height: 22,
                                  type: &quot;edit_text&quot;,
                                  item_id: &quot;team&quot;,
                              }
                          ],
                          type: &quot;view&quot;,
                          elements:
                          [
                              {
                                  item_id: &quot;lbl1&quot;,
                                  type: &quot;static_text&quot;,
                                  name: &quot;&amp;Stamp date&quot;,
                              },
                              {
                                  width: 200,
                                  height: 22,
                                  type: &quot;edit_text&quot;,
                                  item_id: &quot;date&quot;,
                              }
                          ]
                      },
                      {
                          type: &quot;ok_cancel&quot;,
                      }
                  ]
              }
          ]
      },
      initialize: function(dialog) { // where the data in dialog elements is set when the dialog is first activated
          dialog.load({
              &quot;rmas&quot;:this.RMAStage,  
              &quot;free&quot;:this.FreeText,
              &quot;team&quot;:this.CorrectName,
              &quot;date&quot;:this.todaysDate,
          });
      },
      commit: function(dialog) { // where element data is acquired when the user presses the OK button
          var data = dialog.store();
          this.RMAStage = data[&quot;rmas&quot;];
          this.FreeText = data[&quot;free&quot;];
          this.CorrectName = data[&quot;team&quot;];
          this.todaysDate = data[&quot;date&quot;];
      }
  };
  
  /*
   * Pre-fill the dialog text fields with the data below
   */
  /* RMA STAGE (for RMAS to be populated) */
  oDlg.RMAStage = &quot;RMA Stage&quot;;
  
  /* FREE TEXT FIELD (for FREE to be populated)  */
  oDlg.FreeText = &quot;&quot;;
  
  /* NAME AND UNIT (for TEAM to be populated)  */
  var IdentityName, IdentityNameSplit, Unit;
  
  /* Set Organisation Unit */
  Unit = &quot;Parks &amp; Landscapes Team&quot;;  // Unlikely to change
  
  /* Find correctly formatted username from Identity info */
  if((identity.name != null) &amp;&amp; !/^\s*$/.test(identity.name))
      IdentityName = identity.name;
  else
      IdentityName = identity.loginName.replace(/\./g,&quot; &quot;).replace(/\./g,&quot; &quot;).replace(/\b(\w)/g,function(Word,cFst){return cFst.toUpperCase()});
  
  if (IdentityName.indexOf(', ') &gt; -1) { // If the result is &quot;Surname, Firstname&quot; swap the names to make &quot;Firstname Surname&quot;
      IdentityNameSplit = IdentityName.split(', ');
      oDlg.NameAndUnit = IdentityNameSplit[1] + &quot; &quot; + IdentityNameSplit[0] + &quot;, &quot; + Unit;
  }
  else
      oDlg.NameAndUnit = IdentityName + &quot;, &quot; + Unit;
  
  /* FORMATTED DATE FIELD (for DATE to be populated)  */
  var stampDate;
  stampDate = new Date();
  oDlg.TodaysDate = util.printd(&quot;dd mmmm, yyyy&quot;, stampDate);
  
  // Start dialog function
  app.execDialog (oDlg);
  </code></pre>