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

More Dates in Designer

Queue
Registered: Apr 27 2009
Posts: 22
Answered

Hi all,

I have a simple Designer ES (8.2) form that I'm trying to make work but I cannot make it calculate. Such a simple problem, I got it to work on an Acroform but I can't get it to work in Designer.

I need to determine how long a rehired employee was gone. Using Thom's excellent [url=http://www.acrobatusers.com/tutorials/2006/date_time_part1]Date & Time tutorials[/url], I was able to craft the following code when given a Termination Date and the Rehire Date:

var strStart = this.getField("RehireDate").value;
var strEnd = this.getField("TermDate").value;

if(strStart.length && strEnd.length)
{
var dateStart = util.scand("mm/dd/yyyy",strStart);
var dateEnd = util.scand("mm/dd/yyyy",strEnd);
var diff = dateStart.getTime() - dateEnd.getTime();
var oneDay = 24 * 60 * 60 * 1000;
var days = Math.floor(diff/oneDay);
event.value = days;
}
else
event.value = 0;

But I am having difficulty translating this into something Designer recognizes. Here's where I'm at so far:

var strStart = EmpInfoGroup.dtmRehireDate1.rawValue;
var strEnd = EmpInfoGroup.dtmTermDate1.rawValue;

if (dtmStart.length && dtmEnd.length)
{
var dateStart = util.scand("mm/dd/yyyy",strStart);
var dateEnd = util.scand("mm/dd/yyyy",strEnd);
var diff = dateStart.getTime() - dateEnd.getTime();
var oneDay = 24 * 60 * 60 * 1000;
var days = Math.floor(diff/oneDay);
event.value = days;
}
else
event.value = 0;

Any help would be greatly appreciated.

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
There are a number of differences between Acrobat AcroForms JavaScript and LiveCycle Designer JavaScript. Acrobat only has a 'value' and 'valueAsString' properties for a field and they both return the entered value of the field as a number or sting or as forced to a string, but LiveCycle Designer has 'rawValue' and 'formattedValue' properties, 'rawValue' is the internal value used by LiveCycle Designer and 'formattedValue' is the formatted display value.

Also look at the variable names you are using.

// some debugging dataconsole.show();console.clear();console.println("Start date raw: " + dtmRehireDate1.rawValue);console.println("Start date formatted: " + dtmRehireDate1.formattedValue);console.println("End date raw: " + dtmTermDate1.rawValue);console.println("End date formatted: " + dtmTermDate1.formattedValue);// end of debugging statements var strStart = dtmRehireDate1.formattedValue;var strEnd = dtmTermDate1.formattedValue; if(strStart != "" & strEnd != "") {var dateStart = util.scand("mm/dd/yyyy",strStart);var dateEnd = util.scand("mm/dd/yyyy",strEnd);var diff = dateStart.getTime() - dateEnd.getTime();var oneDay = 24 * 60 * 60 * 1000;var days = Math.floor(diff/oneDay);$.rawValue = days;} else {$.rawValue = "";}

Have you looked at using FormCalc?

The date and time fucntions and coding maybe easier in FormCalc.
if (HasValue(dtmTermDate1) & HasValue(dtmRehireDate1) ) thenvar fStart = Date2Num(dtmTermDate1.formattedValue, "MM/DD/YYYY")var fEnd = Date2Num(dtmRehireDate1.formattedValue, "MM/DD/YYYY")$ = fEnd - fStartelse$ = nullendif

George Kaiser

Queue
Registered: Apr 27 2009
Posts: 22
Fantastic, thanks! ;)

EDIT: I wince as I type this but I missed the comment about FormCalc. I guess I just wanted to stick to JavaScript as much as possible? Crummy answer, I know...
Queue
Registered: Apr 27 2009
Posts: 22
Alright, I'm onto Round 2:

Using the excellent JS code you wrote, gkaiseril, I'm trying to tackle my second requirement. I'm trying to take the [b]diff[/b] value and determine what that date is by adding it to an original hire date (dtmOrigHireDate1), and displaying what that date would be. Below is my newly updated code, built from Thom's tutorial's and gkaiseril's instruction:

// some debugging data
console.show();
console.clear();
console.println("Original hire date raw: " + dtmOrigHireDate1.rawValue);
console.println("Original date formatted: " + dtmOrigHireDate1.formattedValue);
console.println("Days gone raw: " + numDaysGone2.rawValue);
console.println("Days gone formatted: " + numDaysGone2.formattedValue);
// end of debugging statements

// Declare Original Hire Date and Equals Days Gone variables.
var dtmFirst = dtmOrigHireDate1.formattedValue;
var numGone = numDaysGone2.formattedValue;

// Find the Accumulated Hire Date by adding numDaysGone2 to OrigHireDate1
if(dtmFirst != "" & numGone != "") {
var dateHire = util.scand("mm/dd/yyyy",dtmFirst);
var dateAdd = (numGone);
var oneDay = 24 * 60 * 60 * 1000;
var sum = dateHire.getTime() + dateAdd * oneDay;
var accDate = new Date(sum);
$.formattedValue = accDate;
} else {
$.formattedValue = "";
}

The console debugging tips is a great idea, thanks for the example, it works nicely. However, my field simply says "Empty" in it. Am I missing a step?