Skip to main content
Participant
March 1, 2017
Question

autopopulate a due date based on todays date and one of two check boxes.

  • March 1, 2017
  • 1 reply
  • 515 views

I have a document that has an ExpireDate field that needs to auto-populate based on whether one checkbox or another is checked (these could also be radio buttons I suppose). The first checkbox "FCheck" needs to auto-populate Today+365 days in the ExpireDate Field. The second checkbox "MCheck" needs to auto-populate Today+182 days in the ExpireDate Field. If neither box is checked, the field should be blank. (There should never be a situation when both should be checked, so I guess I should change these to radio buttons).

I've tried every forum imaginable, but can't seem to nail this down. Any help would be greatly appreciated. Thank you!

This topic has been closed for replies.

1 reply

Inspiring
March 2, 2017

You will need to convert the current date string into a JavaScript date object (use the util.scand method), then use one of several possible methods to add the number of days to that date object (either by add the number of days in millisceconds or using the setDayte method), and use the util.printd method to format the date object to a readable date string.

What will happen if neither box is checked?

Participant
March 2, 2017

I have tried both the millisecond approach but seem to be getting something wrong (I'm assuming with the checkbox condition). If neither box is checked, it should remain blank.

try67
Community Expert
Community Expert
March 2, 2017

Give both boxes the same name (say "Check"), but different export values (say "M" and "F"), then use this code as the custom calculation script for ExpireDate:

var checkboxValue = this.getField("Check").valueAsString;

if (checkboxValue=="Off") event.value = "";

else {

    var d = new Date();

    var daysToAdd = (checkboxValue=="F") ? 365 : 182;

    d.setDate(d.getDate()+daysToAdd);

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

}