Expand my Community achievements bar.

## Date Field

Level 4
I am creating a timesheet for our organisation and am wondering if there is anyway that our employees only have to enter Monday's date and the following dates will automatically be generated. I have been able to do this in excel but I am not sure how to do this in Livecycle.

Your knowledge would be greatly be appreciated.

Julie
12 Replies

Not applicable
Julie,

Given a form with the root name 'form1', an untitled subform, and five occurrences of a DateTimeField called 'dtf', you could add the following FormCalc script on exit event of 'dtf[0]' to calculate the next four days based upon the date selected for 'dtf[0]'.

form1.#subform[0].dtf[0]::exit - (FormCalc, client)

xfa.form.form1.#subform.dtf[1] = Num2Date((Date2Num(xfa.form.form1.#subform.dtf[0].formattedValue,"YYYY-MM-DD")+1),"YYYY-MM-DD");

xfa.form.form1.#subform.dtf[2] = Num2Date((Date2Num(xfa.form.form1.#subform.dtf[0].formattedValue,"YYYY-MM-DD")+2),"YYYY-MM-DD");

xfa.form.form1.#subform.dtf[3] = Num2Date((Date2Num(xfa.form.form1.#subform.dtf[0].formattedValue,"YYYY-MM-DD")+3),"YYYY-MM-DD");

xfa.form.form1.#subform.dtf[4] = Num2Date((Date2Num(xfa.form.form1.#subform.dtf[0].formattedValue,"YYYY-MM-DD")+4),"YYYY-MM-DD");

The FormCalc data functions work nicely because they are smart enough to cut across months and years.

Note, I have defined the display and edit patterns on 'dtf[0]' through 'dtf[4]' as date{YYYY-MM-DD}. A different (consistent) pattern would work equally well.

Steve

Not applicable
HI Steve,

Complete noob here- but have similar need for a vacation request form-

my ?: can you apply the form calc you describe above to fields on a table or in separate text(date?) fields with out having to use the subforms?

Or does this calculation only work when it applies to subforms?

While i'm asking the guru- is there any way to show a calendar that only the 'sunday's' are clickable? Reason being our work week begins on a sunday, and to fill in the rest of the week, this would give the user Only sundays to choose from.

TIA

eric

Level 4
Thanks Steve,

I have nearly to it to work using the following scripting:

form1.#subform[0].Table2.Row2.Cell2::exit - (FormCalc, client)

xfa.form.form1.#subform.Table2.Row2.Cell3 = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row2.Cell2.formattedValue,"YYYY-MM-DD"))+1,"YYYY-MM-DD");

xfa.form.form1.#subform.Table2.Row2.Cell4 = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row2.Cell2.formattedValue,"YYYY-MM-DD"))+2,"YYYY-MM-DD");

xfa.form.form1.#subform.Table2.Row2.Cell5 = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row2.Cell2.formattedValue,"YYYY-MM-DD"))+3,"YYYY-MM-DD");

xfa.form.form1.#subform.Table2.Row2.Cell6 = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row2.Cell2.formattedValue,"YYYY-MM-DD"))+4,"YYYY-MM-DD");

The only problem that I have now is that when Monday's date is entered eg 16-Mar-09, Tuesday's date is 01-Jan-00 and so on. How do I make Tuesday's date follow on from the 16-Mar-09 eg 17 Mar-09?

Regards

Julie

Not applicable
Eric,

The form hierarchy always includes a subform. When you generate a new blank template you will see '(untitled Subform) (page 1)' in the form hierarchy. In this case the page is a subform. A form is typically constructed with multiple subforms on a page. Depending on the complexity of the form you may have subforms nested in subforms.

It is possible to access an object without the subform name and apply calculations, such as the FormCalc date function. Whether or not it yields predictable results in all circumstances depends upon the form. There are different ways to access objects in scripts and they are documented here:

On the DateTime object, it is not possible to customize the dates exposed in the widget. It would be possible to derive the current date, work back to Sunday, and populate date fields for the week, however.

Steve

Not applicable
Julie,

The display and edit patterns on your table are not consistent with the formattedValue in the function call. You have the patterns defined as date{DD-MMM-YY}. The pattern on the function is date{YYYY-MM-DD}.

You can either change the pattern on the function call to DD-MMM-YY or you can change the display and edit patterns on the table to YYYY-MM-DD.

Steve

Not applicable
Is it somehow possible to ask, if a date is in some kind of range?

F.ex. a user has to send a form at least 1 month before/after an event is happening/has happened. If it is out of that range, the form should apply an errormessage.

Is it possible to compare the date he enters to the sysdate?

Not applicable
Sure ....you can use a function to channge the date into a number of days from a set point in time (called an epoch). There is a simple FormCalc function called Date2Num that will return a number of days since th eepoch. You can add a subtract 30 days from it and see if the Date2Num that the user entered is in that range.

Make sense?

Not applicable

Just looked up the date formatations today and wondered what epoch really is.

Thanx ^^

(One more trick in my little trickbox. ^^)

Not applicable
HI Steve-

I see says the blind man....OK, so I'll do as demonstrated, Thanks for the explanation.

One follow up ?: using the DTF object to pull a calendar date, when the object pops up and you mouse out of the box to get the pull down for the calender it fires the script -mouse out event- How do i prevent it from happening?

i changed the event to exit, but now the user has to click outside the box to get script to fire.

I apologize in advance for what prolly is a simply issue...

eric

Not applicable
HI Steve,

I appreciate your help on the above..now i want to extend that script..and i'm getting an error.

I have a table- sunday......saturday.

I've applied the following to calculate the dates based on user intput for a 'sunday':

NOW- I'd like to have the same calculation apply to 'monday', subtracting a day to get a 'sunday' value, add days for the rest of the week...

so i've added the same FormCalc script, but when i run this i'm getting a "Datetimefield(0)

validation failed.

Is this because the script is trying to run it against the value created when the 'Monday' script ran? how to i get this to 'thro no error'?

all fields are datetimefields, same format, no binding, type is user entered/optional.

I have tried setting the initial value to 'sunday' to null..didn't work...

i'm outta ideas....

Thanks In Advance- from a complete Noob....

eric

Not applicable
OK- mea culpa...I'm an idiot..

forgot that there is an inherrent validation script in the xml- all i had to do was remove this?!?!? and it works fine!!

e

Not applicable

I use something similar for a two week timesheet. User selects "Pay Period End" date by clicking in date field and choosing the date for 2nd Sunday from the calendar. System displays that date in form . I then use offsets from that date ( -0 to -13) to populate 14 dates for Days on form.

For each Day date object used, you need to modify calculate::script for  destination object name and offset value

Copy the first line below (feel free to include my //comments too) and paste it in the calculate event (FormCalc) for each Day date object.

If user enters date for Monday then date object offset for Friday would be +4, etc.

OffsetDate1.rawValue = Num2Date(Date2Num(StartEndDate.formattedValue, "DD-MMM-YY") +/-zz, "DD-MMM-YY" )

//Usage: Autofill Date objects on form when user enters a date.

//Language:FormCalc; Event:Calculate; Date object:Calculated - Read Only; Data Pattern binding:"DD-MMM-YY"

// Method:Cast user entered date as number,add offset,re-cast number as date,assign value to date object.

//<Pseudo code>

//DayObjectName.unformatted = makeDateFrom#(make#fromDate objectname.formatted(date, “source date format") +- offset, "dest object date format")

// </Pseudo code>

//OffsetDate1 is object name for Day receiving the date: StartEndDate is the date entered by user.

// +/-zz is # days before(-)or after(+)the start/end date

//binding of date object can be modified but the “Data Pattern” used MUST be defined in your script

HINT: Format one date object with script and binding then drag it to Favorites Library as a date/time object called  FVDT (or PVDT) so it can be reused. Hope this helps Ed McGrath C.E.T.

Message was edited by: Ed McGrath