Skip to main content
January 24, 2019
Answered

Getting a field autofilled based on dates

  • January 24, 2019
  • 1 reply
  • 1426 views

Hello,

I have been trying to find a solution to the below issue for the last 3 days.

I am creating a form. My skill level is beginner.

I am using Adobe Pro DC.

The form in question has a date filed calendar. User can also enter their own date (YYYY-MM-DD) or chose a date on the pop-up calendar.

I have an other field which will contain a value (based on the date).

If the date entered is between April 1, 2018 and March 31, 2019, the field will display "2018-19"

If the date entered is between April 1, 2019 and March 31, 2020, the field will display "2019-20".

ex: user enters the following date:

Result:

PR (is autogenerated based on the type of ticket - This is already working, I do not need assistance here)

12345 (ticket number will be manually entered by the operator - I will probably just add an additional text field.)

Thank you in advance for any help you might be able to provide.

Valerie

This topic has been closed for replies.
Correct answer try67

OK, then you can use this code as the custom calculation script of the Ticket field:

(function() {

    var startDate1 = new Date(2018, 3, 1, 0, 0, 0, 0).getTime();

    var endDate1 = new Date(2019, 2, 31, 23, 59, 59, 999).getTime();

    var startDate2 = new Date(2019, 3, 1, 0, 0, 0, 0).getTime();

    var endDate2 = new Date(2020, 2, 31, 23, 59, 59, 999).getTime();

    event.value = "";

    var s = this.getField("DateOrigReq").valueAsString;

    if (s=="") return;

    var d = util.scand("yyyy-mm-dd", s);

    if (d==null) return;

    var v = d.getTime();

    if (v>=startDate1 && v<=endDate1) event.value = "2018-19";

    else if (v>=startDate2 && v<=endDate2) event.value = "2019-20";

})();

1 reply

try67
Community Expert
Community Expert
January 24, 2019

What if the date entered is not within those periods?

try67
Community Expert
Community Expert
January 24, 2019

Also, what's the name of the date field?

January 24, 2019

The Date filed name is : DateOrigReq

But I can easily change it.

The ticket filed is currently called : Ticket

A more suitable name can be given later.

Thank you,

Valerie