3 Replies Latest reply on Mar 29, 2016 9:54 AM by yeungyam

    Yesterday date, but want manual exception

    yeungyam Level 1

      I have a form in which it shows yesterday's date when you open it, unless it is a Monday then it shows Friday's date. The date is separated in 3, so I have ScanDate_month, Scandate_year, and ScanDate_day.

      When the form opens, a hidden field (Today) sets today's date and another sets the day of the week (WeekDay).

       

      var m = this.getField("ScanDate_month");
      var y = this.getField("ScanDate_year");
      var fld = this.getField("ScanDate_day");
      var d1 = new Date();
      var num = d1.valueOf();
      
      if(this.getField("WeekDay").value == "Mon")
      {
      num += -(1000 * 60 * 60 * 24 * 3);
      }
      else
      {
      num += -(1000 * 60 * 60 * 24);
      }
      
      m.value = util.printd ("mm", new Date(num));
      fld.value = util.printd ("dd", new Date(num));
      y.value = util.printd ("yyyy", new Date(num));
      
      

       

      I would like to add some exceptions for Holidays.

      For example, if today's date is 03/29/2016, instead of showing 03/28/2016 it would show 03/24/2016 because Friday and Monday were Holidays.

      I realize that I will need to add each Holiday manually in the script, but that would be fine.

       

      So I used else if, but it doesn't accept my script saying there is an error after the first exception

      if(this.getField("WeekDay").value == "Mon")
      {num += -(1000 * 60 * 60 * 24 * 3);}
      
      else if
      ((this.getField("WeekDay").value == "Tue") || (this.getField("WeekDay").value == "Wed") || (this.getField("WeekDay").value == "Thu") || (this.getField("WeekDay").value == "Fri"))
      {num += -(1000 * 60 * 60 * 24);}
      
      else if
      (this.getField("Today").value == "03/29/2016");
      {num += -(1000 * 60 * 60 * 24 * 5);}
      
      else if
      (this.getField("Today").value == "05/24/2016");
      {num += -(1000 * 60 * 60 * 24 * 4);}
      
      else if
      (this.getField("Today").value == "07/04/2016");
      {num += -(1000 * 60 * 60 * 24 * 4);}
      
      

       

      Can someone help me figure out what is the error after the first exception?