These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Dilemma with automatic Date calculation

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Answered

Hello,

i've got a problem that drive me crazy.
In a XML-form I use a JS by thomp, that I found in a tutorial.
The JS works in the calculate event of a textfield in flowtext to output the expire-date of this form.
To avoid that the JS will be calculated everytime the filled form is opened again I used an IF-condition for it.

if (Formular1.Seite1.Body.Dienstleitungen.EndDatum.rawValue == null)
{
// Get todays date
var RightNow = new Date();
// Calculate todays Milliseconds
var msRightNow = RightNow.getTime();
// Calculate 7 days in Milliseconds
var sevenDays = 7 * 24 * 60 * 60 * 1000;
// Calculate final date
var finalTime = msRightNow + sevenDays;
// Convert to date
var theNewDate = new Date(finalTime);
// Output the final date
event.value = util.printd("dd.mm.yyyy",theNewDate);
}
else
{}

In the preview of Designer this works perfectly and also in Acrobat/Reader.
But I have to enabe User Rights for the form, that causes a dilemma I could not solve until now.
After enabling the rights and saving the form, the IF-condition is never NULL again and there is always an expire-date in the form that has been calculated before enabling the rights.
I have a reset-all-button in the form with that I can force the form to calculate a new expire-date, but that's no a end user friendly solution to say: "Please reset the form after opening even if it is blank".

So I need a solution.
Please help!

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

My Product Information:
LiveCycle Designer, Windows
JennD
Registered: Jan 8 2009
Posts: 18
Have you tried putting the reset script just before your if statement?

I'm just now learning this scripting thing, but I've noticed that the code seems to execute in the order it reads it.

Just throwing out an idea...

Jenn D.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Enabling the Extended Rights opens the form and processes the script for setting the date. You might try add another control field to allow for this processing.

George Kaiser

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
gkaiseril wrote:
Enabling the Extended Rights opens the form and processes the script for setting the date. You might try add another control field to allow for this processing.
Hello again.

I was searching for a workaround and replaced the JS with FormCalc.

In the form there is now a normal date field that calculates the todays date when the forms is opened with these script in form:ready event.

if ($.rawValue==null)then
$.rawValue = num2date(date(), "DD.MM.YYYY")
else $.rawValue
endif

For the expiring date I put a text field into a flowtext field the uses the following script in the calculate event.

var TodayIs = Date2Num(Form1.Page1.Body.DateField.rawValue, "DD.MM.YYYY")
var InSevenDays = TodayIs + 7
var NextWeek = Num2Date(InSevenDays, "DD.MM.YYYY")
Form1.Page1.Body.ExpireDate.rawValue = EndDatum

This method works good, as long there is no need to change the date in the DateField.
If it is changed, the ExpireDate is recalculated always to 07.01.1900.
It seems that the value of TodayIs is not recognized anymore by the calculation.

Any idea about this?

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
OK, I think I got it work!
There is no need for variables.
At least you only need 2 lines of code, if you do not need the If-conditions.

1. The date/time field calculates the current date when the form is opened first time with this script.

if ($.rawValue==null)then
$.rawValue = Num2Date(date(), DateFmt(2)) //get current date
else $.rawValue
endif

2. The expiring date is shown in a flowtext and calculated by another script, that checks the date/time field value and adds 7 days to the value.

if (Form1.Page1.Body.Dates.dateSign.rawValue==null)then
$.rawValue = ""
else
Num2Date(Date2Num(Form1.Page1.Body.Dates.dateSign.formattedValue, DateFmt(2)) + 7, DateFmt(2)) // get value of date/time field and add 7 days
endif

The positive thing is, users can change the date in the date/time field and the expiring date is recalculated just in time.
And, I can avoid trouble with the fields values after enabling user rights, cause I can clear the date/time field before enabling and in this case the expiring date is also clear.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs