Skip to main content
Participant
March 26, 2020
Question

Autocalculate EndDate - 18 months minus 1 day from StartDate

  • March 26, 2020
  • 2 replies
  • 716 views

I have already a lot of different pdf forms used to register learners as they start their apprenticeship with my company. Different programs mean different length. 

 

Long story short, I have this idea to make the form more convenient where people feed in information like "Learner's name", "Coach", Start Date", choose the programme from the drop down list and click a button and corresponding forms are generated. I am using Adobe Livecycle. However, I got stumped on calculated date field. 

 

1. How do I calculate the EndDate of 18 months minus 1 day from the StartDate. I tried using the script that works on Adobe Acrobat Pro for my current forms but for some reason it doesn't work in Adobe LiveCycle. I have a StartDate field for people to input the info and EndDate field is automatically calculated.

 

var date= util.scand("dd/mm/yyyy", this.getField("StartDate").value);
date.setMonth(date.getMonth()+18)
date.setDate(date.getDate()-1)
if (this.getField("StartDate").value!="")
{
event.value=util.printd("dd/mm/yyyy",date)
}
else
{event.value=""}

 

2. My second question is if I have different lengths of programs of 13-18 months, how do I improve the script to reflect that?

 

Many thanks in advance

Thao

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
March 26, 2020

In XFA forms the "this" keyword refers to the current field object, not the document. And the result of a calculation is simply the last value in the calculation script. If the value is being set from a non-calcualtion, then it is set with the "rawValue" field property.  

 

So, very different scripting rules. You should read about them if you're going to script in an XFA doc. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
March 26, 2020

Why are you using LCD? It makes things much more complicated, and is supported on far less systems.

Unless there's a really good reason I would strongly suggest switching to a "normal" Acrobat form.

thaongAuthor
Participant
March 26, 2020

I want to create an interactive form .i.e Coach picks Progamme and company size and the corresponding pages appear. Ca this be done with Adobe Acrobat Pro? I used Lifecycle to create a registration form with buttons to add or remove lines and fields hidden which only appear based on what radio button is checked. That's what gave me the idea to make this master form. 

try67
Community Expert
Community Expert
March 26, 2020

Yes, it's possible in an Acrobat form, although in a more limited way, since you can't "re-flow" the entire page. You can show/hide fields, or even pages. If you hide a field there will just be an empty spot where it was located, unless you move other fields to take its place.