Skip to main content
Participant
June 7, 2018
Question

Fields that auto calculate date based on user input date.

  • June 7, 2018
  • 1 reply
  • 447 views

I have a form that requires 7 day history from date of application. The user inputs the application date. I then have 7 separate fields that should auto calculate the past 7 days from the user input. For example: user input = 06/07/2018

Prior 7Prior 6Prior 5Prior 4Prior 3Prior 2Prior 1
05/31/201806/01/201806/02/201806/03/201806/04/201806/05/201806/06/2018


With the dates in the table above being auto-calculated in 7 separate fields. Let me know if I'm not making any sense. Also, here's something that I found to try and adapt to what I need, but my coding knowledge is small and not in Java at all haha so any help is appreciated.

var dateString = this.getField("Date of Application").value; 

if (dateString=="") event.value = ""; 

else { 

    var d = util.scand("mm/dd/yyyy", dateString); 

    d.setDate(d.getDate()-7); 

    event.value = util.printd("mm/dd/yyyy", d); 

Thanks.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
June 7, 2018

The code you found is correct, for the last day in the series. What happens when you place it as the custom calculation script of that field?

Participant
June 7, 2018

When I put it in the prior 7 field nothing happens. Am I supposed to do something special to trigger the script?

Edit: I was putting the script in the validation field. I put it in the calculation field and it worked haha. I feel dumb, but thank you for talking it out with me.

try67
Community Expert
Community Expert
June 7, 2018

:-) Not a problem!