1 Reply Latest reply on Oct 6, 2010 10:51 PM by George_Johnson

    MULTI AUTO DATE FIELDS

    StevenThompson

      Looking for a script that will do the following,

       

      I need to firstly have a text field auto populate with today’s date. I’m using the following script.

       

      var f = this.getField("RaisedDate");
      f.value = util.printd("mmm/d/yyyy", new Date());

       

      Then i need a 2nd text field to populate depending on what dropdown is chosen in a drop down.

       

      Basically the code im looking for is something like

       

      If "dropdownbox option 1" is choosen, TargetDate(free text field) = RaisedDate + 24 hours(1day)

      If "dropdownbox option 2" is choosen, TargetDate(free text field) = RaisedDate + 48 hours(2days)

      If "dropdownbox option 3" is choosen, TargetDate(free text field) = RaisedDate + 72 hours(3days)

       

      If anyone has a solution as I’m only new to scripting please advise as it would be much appreciated.

        • 1. Re: MULTI AUTO DATE FIELDS
          George_Johnson MVP & Adobe Community Professional

          Use the following as the custom calculation script of the TargetDate field. It assumes that the combo box (export) values are restricted to being a number.

           

          (function () {

           

              // Get date from field
              var v = getField("RaisedDate").value;

           

              // Get the number of days to add from combo box
              var days_to_add = getField("DaysCombo").value;
             
              if (v) {

           

                  // Convert string to date
                  var d = util.scand("mmm/d/yyyy", v);

           

                  // Add days
                  d.setDate(d.getDate() + days_to_add);

           

                  // Set value of this field to the new date
                  event.value = util.printd("mmm/d/yyyy", d);

           

              } else {

           

                  // Blank field if no date available
                  event.value = "";
              }

           

          })();

           

          Replace "DaysCombo" in the code above to match the name of the combo box field you're using.