5 Replies Latest reply on Mar 18, 2016 7:59 AM by gkaiseril

    Fillable PDF that populates a future buisness day

    48kilos

      I have created a fillable PDF document that end users will utilize to book an event. The end user will enter the date they want the event to happen.   Further down the document i would like several read only fields to auto-populate with business dates along the way that show the end user some benchmarks of when things will happen.

       

       

      Example:

      End user enters an event date into TextBox1

      Textbox2 auto-populates with a date X Business days before the event showing when the End User will receive a communication confirming that the event is still scheduled

      TextBox3 will Auto-populate with a date Y business days before the event showing end user when the set-up for the event will begin

      Finally TexBox4 with auto-populate with a date Z business days before the event showing when the end user may inspect the event site

       

       

       

      I am able to have all the text boxes auto-populate with Calendar days using the below code.  However I want to be able to execute this doc using Business days not calendar days.    Is this possible?

       

       

       

       

       

      For the calendar days I have a Document script called "countDays"

      function countDays(z){

      var a = (1000*60*60*24) * z;

      var b = 0;

      var c = new Date();

      var d = this.getField("TextBox1").value;

      if(d!=""){

      var e = Date.parse(util.scand("mm/dd/yy", d));

      c.setTime(e + a);

      event.value = util.printd("mm/dd/yy",c);}

      }

       

      TextBox2 then has a Custom Calculate script of

      countDays(-14)

       

      TextBox3 then has a Custom Calculate script of

      countDays(-7)

       

      TextBox4 then has a Custom Calculate script of

      countDays(-2)

        • 1. Re: Fillable PDF that populates a future buisness day
          try67 MVP & Adobe Community Professional

          By "business days" do you mean non-weekend days? What about holidays?

          And what should happen if the calculated day falls on a non-business day? Should it move forward or backwards?

          • 2. Re: Fillable PDF that populates a future buisness day
            48kilos Level 1

            Great question Try67!

             

            Ideally it would take into consideration federal holidays, but i will be ok with just calculating weekdays (mon-fri)

             

             

            The benchmark days will always be business days before the event, even if the event date selected by the end user is a non-business day.   Example:  if the event date is a Sunday, then 1 business day before would be the Friday prior.

            • 3. Re: Fillable PDF that populates a future buisness day
              try67 MVP & Adobe Community Professional

              Taking holidays into consideration is possible, but more complex.

              Just checking if the result is Saturday or Sunday is easy. Just use the getDay method of the Date object.

              If you find out that it is either of these days then add or subtract 1 day to the variable, using the setTime method.

              • 4. Re: Fillable PDF that populates a future buisness day
                lifeis2short

                Did you ever figure out how to do this?  I am looking for the exact same solution.  If you have an example you could share it would be awesome.

                • 5. Re: Fillable PDF that populates a future buisness day
                  gkaiseril MVP & Adobe Community Professional

                  There are many posts on the internet for this function in JavaScript;

                   

                  The following uses the date object for the beginning and ending dates to return the number of business days or a -1 if the ending date is before the starting date.

                   

                  function calcBusinessDays(dDate1, dDate2) {         // input given as Date objects

                  var iWeeks, iDateDiff, iAdjust = 0;

                    if (dDate2 < dDate1) return -1;                 // error code if dates transpose6.
                    var iWeekday1 = dDate1.getDay();                // day of week
                    var iWeekday2 = dDate2.getDay();

                    iWeekday1 = (iWeekday1 == 0) ? 7 : iWeekday1;   // change Sunday from 0 to 7
                    iWeekday2 = (iWeekday2 == 0) ? 7 : iWeekday2;
                    if ((iWeekday1 > 5) && (iWeekday2 > 5)) iAdjust = 1;  // adjustment if both days on weekend
                    
                    Weekday1 = (iWeekday1 > 5) ? 5 : iWeekday1;    // only count weekdays
                  iWeekday2 = (iWeekday2 > 5) ? 5 : iWeekday2;

                    // calculate differnece in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)
                    iWeeks = Math.floor((dDate2.getTime() - dDate1.getTime()) / 604800000)

                    if (iWeekday1 <= iWeekday2) {
                      iDateDiff = (iWeeks * 5) + (iWeekday2 - iWeekday1)
                    } else {
                      iDateDiff = ((iWeeks + 1) * 5) - (iWeekday1 - iWeekday2)
                    }

                    iDateDiff -= iAdjust                            // take into account both days on weekend

                    return (iDateDiff + 1);                         // add 1 because dates are inclusive
                  }

                   

                  I will let you workout how to convert the date strings to date objects.