Date field - default to today

7,431 views
Skip to first unread message

Worst, Debbie

unread,
Mar 23, 2010, 2:21:12 PM3/23/10
to live...@googlegroups.com
I have a date field that the user wants to default to "today".  The problem I'm having is that on "initialize" is where I would put the code for the date to be populated, but when you save and close and then re-open it changes the date…..anyone have any idea on how I could have this date field remain what was originally input?
 
Thanks,
 

********************************************************************** The content of this e-mail message and any attachments are confidential and may be legally privileged, intended solely for the addressee. If you are not the intended recipient, be advised that any use, dissemination, distribution, or copying of this e-mail is strictly prohibited. If you receive this message in error, please notify the sender immediately by reply email and destroy the message and its attachments. **********************************************************************

Duane Nickull

unread,
Mar 23, 2010, 2:30:05 PM3/23/10
to Adobe LiveCycle Developers
Did you try the “Preserve scripting changes” on your form?

File -> Form Properties
Choose “Defaults” tab
Select “Preserve Scripting changes to form when saved” and make sure it is set to automatic.

Let me know if that worked.

Duane

Worst, Debbie

unread,
Mar 23, 2010, 2:44:04 PM3/23/10
to live...@googlegroups.com
Yes it is checked and I verified that it will change because I put the time in also and the time changed when I opened the form again.


From: live...@googlegroups.com [mailto:live...@googlegroups.com] On Behalf Of Duane Nickull
Sent: Tuesday, March 23, 2010 2:30 PM
To: Adobe LiveCycle Developers
Subject: Re: Date field - default to today

--
You received this message because you are subscribed to the Google Groups "Adobe LiveCycle Developers" group.
To post to this group, send email to live...@googlegroups.com.
To unsubscribe from this group, send email to livecycle+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/livecycle?hl=en.

Jono Moore

unread,
Mar 23, 2010, 2:48:06 PM3/23/10
to Adobe LiveCycle Developers
You need to check whether there is a value in the field or not. If no
value, then do the date routine - if there is a value then leave it
alone.

//check if field has value and assign date if no value
if (fieldName.rawValue == null){
this.rawValue = new Date();
}
//assign current value if field has a value already
else {
this.rawValue = this.rawValue;
}

Actually on thinking about it the else may not be needed, I've just
always had it in there for some reason.

On Mar 23, 11:21 am, "Worst, Debbie" <dwo...@GAIC.COM> wrote:
> I have a date field that the user wants to default to "today".  The problem I'm having is that on "initialize" is where I would put the code for the date to be populated, but when you save and close and then re-open it changes the date.....anyone have any idea on how I could have this date field remain what was originally input?

Duane Nickull

unread,
Mar 23, 2010, 2:52:35 PM3/23/10
to Adobe LiveCycle Developers
That should work fine.   Debbie – the problem, is that if you put one script on the initialize event, it will fire every time the event is thrown so each new user will get a new date.  I had assumed you had cast the date to a variable.  One easy way to do this is using Jono’s script and set a hidden field to equal the date the first time a user opens the form.  On subsequent times, the date can be read in (using his “if..else) and used to set the date.

A more elegant solution for this would be to use LiveCycle Workspace on ES2.  Including forms as part of a long lived business process is LC ES’s forte.

Duane
--
You received this message because you are subscribed to the Google Groups "Adobe LiveCycle Developers" group.
To post to this group, send email to live...@googlegroups.com.
To unsubscribe from this group, send email to livecycle+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/livecycle?hl=en.


Worst, Debbie

unread,
Mar 23, 2010, 3:11:18 PM3/23/10
to live...@googlegroups.com
so do I use a datefield object?  If so, it still is changing the time so it will change the date then also.
 
I'm confused??


From: live...@googlegroups.com [mailto:live...@googlegroups.com] On Behalf Of Duane Nickull
Sent: Tuesday, March 23, 2010 2:53 PM

To: Adobe LiveCycle Developers
Subject: Re: Date field - default to today

Duane Nickull

unread,
Mar 23, 2010, 3:15:02 PM3/23/10
to live...@googlegroups.com
yes - Jono's script should work fine.

D
********
22nd Century (my band) - http://22ndcenturyofficial.com/
Twitter - @duanechaos
********


Worst, Debbie

unread,
Mar 23, 2010, 3:34:00 PM3/23/10
to live...@googlegroups.com
Well, I'm going to do an overnight test to see if tomorrow when I open the form that currently has todays date in it if it changes to the current date tomorrow, because when I had it formatted as date/time, the time changed every time I opened the form, so therefore I would assume that the date will change also.


From: live...@googlegroups.com [mailto:live...@googlegroups.com] On Behalf Of Duane Nickull
Sent: Tuesday, March 23, 2010 3:15 PM
To: live...@googlegroups.com

Duane Nickull

unread,
Mar 23, 2010, 3:40:22 PM3/23/10
to Adobe LiveCycle Developers
You could use a Date/Time field to test.

D

Worst, Debbie

unread,
Mar 23, 2010, 4:00:56 PM3/23/10
to live...@googlegroups.com
I did and the time changed each time I opened the form which would lead me to believe that the date will change also.


From: live...@googlegroups.com [mailto:live...@googlegroups.com] On Behalf Of Duane Nickull
Sent: Tuesday, March 23, 2010 3:40 PM

Jono Moore

unread,
Mar 23, 2010, 4:52:04 PM3/23/10
to Adobe LiveCycle Developers
I had to go back and check my script as I was going from memory...I
actually use a text field not a date field.

Part of the problem might be how your date/time field is setup and
getting its values. So, not knowing how you're getting the value,
maybe try the following.

You could use a text field and use the something like the following
FormCalc script to get what you need for date and time (FormCalc is
easier for dealing with dates than JavaScript. You can get the values
for DateFmt() and TimeFmt() in Help):

if ($.rawValue == null)
then
var d = num2date(date(), DateFmt(3))
var t = num2time(time(), TimeFmt(2))
$ = concat(d, Space(1), t)
else ($.rawValue)
endif


Hope that helps!

P.S.
If you're getting tricky with FormCalc you could do the whole date
calculation in one line:
$ = concat(num2date(date(), DateFmt(3)), Space(1), num2time(time(),
TimeFmt(2)))


On Mar 23, 1:00 pm, "Worst, Debbie" <dwo...@GAIC.COM> wrote:
> I did and the time changed each time I opened the form which would lead me to believe that the date will change also.
>
> ________________________________
> From: live...@googlegroups.com [mailto:live...@googlegroups.com] On Behalf Of Duane Nickull
> Sent: Tuesday, March 23, 2010 3:40 PM
> To: Adobe LiveCycle Developers
> Subject: Re: Date field - default to today
>
> You could use a Date/Time field to test.
>
> D
>
> On 3/23/10 12:34 PM, "Worst, Debbie" <dwo...@GAIC.COM> wrote:
>
> Well, I'm going to do an overnight test to see if tomorrow when I open the form that currently has todays date in it if it changes to the current date tomorrow, because when I had it formatted as date/time, the time changed every time I opened the form, so therefore I would assume that the date will change also.
>
> ________________________________
> From: live...@googlegroups.com [mailto:live...@googlegroups.com] On Behalf Of Duane Nickull
> Sent: Tuesday, March 23, 2010 3:15 PM
> To: live...@googlegroups.com
> Subject: Re: Date field - default to today
>
> yes - Jono's script should work fine.
>
> D
> ********

> 22nd Century (my band) -http://22ndcenturyofficial.com/
> Twitter - @duanechaos
> Blog -http://technoracle.blogspot.com


> ********
>
> On 23-Mar-10, at 12:11 PM, Worst, Debbie wrote:
>
> so do I use a datefield object?  If so, it still is  changing the time so it will change the date then also.
>
> I'm confused??
>
> ________________________________
> From: live...@googlegroups.com [mailto:live...@googlegroups.com]  On Behalf Of Duane Nickull
> Sent: Tuesday, March 23, 2010 2:53  PM
> To: Adobe LiveCycle Developers
> Subject: Re: Date field  - default to today
>

> That should work fine.   Debbie - the  problem, is that if you put one script on the initialize event, it will fire  every time the event is thrown so each new user will get a new date.  I  had assumed you had cast the date to a variable.  One easy way to do this  is using Jono's script and set a hidden field to equal the date the first time  a user opens the form.  On subsequent times, the date can be read in  (using his "if..else) and used to set the date.


>
> A more elegant solution  for this would be to use LiveCycle Workspace on ES2.  Including forms as  part of a long lived business process is LC ES's  forte.
>
> Duane
>

> On 3/23/10 11:48 AM, "Jono Moore" <jono.mo...@gmail.com>  wrote:


>
> You need to check whether there is a value in the  field or not. If no
> value, then do the date routine - if there is a value  then leave it
> alone.
>
> //check if field has value and assign date if  no value
> if (fieldName.rawValue == null){
>   this.rawValue =  new Date();}
>
> //assign current value if field has a value  already
> else {
>   this.rawValue =  this.rawValue;
>
> }
>
> Actually on thinking about it the else may not be  needed, I've just
> always had it in there for some reason.
>
> On Mar  23, 11:21 am, "Worst, Debbie" <dwo...@GAIC.COM> wrote:
>
> > I have a date  field that the user wants to default to "today".  The problem I'm  having is that on "initialize" is where I would put the code for the date to  be populated, but when you save and close and then re-open it changes the  date.....anyone have any idea on how I could have this date field remain  what was originally input?
>
> > Thanks,
>
> >  ********************************************************************** The  content of this e-mail message and any attachments are confidential and may  be legally privileged, intended solely for the addressee. If you are not the  intended recipient, be advised that any use, dissemination, distribution, or  copying of this e-mail is strictly prohibited. If you receive this message  in error, please notify the sender immediately by reply email and destroy  the message and its attachments.  **********************************************************************
>
> --
> You  received this message because you are subscribed to the Google Groups "Adobe  LiveCycle Developers" group.
> To post to this group, send email to live...@googlegroups.com.
> To  unsubscribe from this group, send email to livecycle+...@googlegroups.com.

> For  more options, visit this group athttp://groups.google.com/group/livecycle?hl=en.


>
> ---
> Adobe LiveCycle Enterprise Architecture -  http://www.adobe.com/products/livecycle/
> My  TV Show -http://tv.adobe.com/show/duanes-world/

> My  Blog -http://technoracle.blogspot.com/
> My Band -http://22ndcenturyofficial.com/
> Twitter -http://twitter.com/duanechaos


>
> ---
> Adobe LiveCycle Enterprise Architecture -http://www.adobe.com/products/livecycle/
> My TV Show -http://tv.adobe.com/show/duanes-world/

> My Blog -http://technoracle.blogspot.com/
> My Band -http://22ndcenturyofficial.com/
> Twitter -http://twitter.com/duanechaos


>
> --
> You received this message because you are subscribed to the Google Groups "Adobe LiveCycle Developers" group.
> To post to this group, send email to live...@googlegroups.com.
> To unsubscribe from this group, send email to livecycle+...@googlegroups.com.

> For more options, visit this group athttp://groups.google.com/group/livecycle?hl=en.

Duane Nickull

unread,
Mar 23, 2010, 5:49:33 PM3/23/10
to Adobe LiveCycle Developers
Debbie:

Pure genius?

The attached two forms might be a good workaround.  You will be able to open the first one with Acrobat and the date will default to the system date/time.  When you place the cursor into the date/time field and then exit that field (it is fully editable), the original Date/Time becomes hidden and it’s value it copied to a second date/time field which then becomes visible.  These could be laid out on top of each other.  The second date/time field is “read only” so subsequent users cannot change that date.  The initial user can still set the first date/time if they want to something other than the system.  If you want it to always be read from the system, make this one “read only – calculated”.

If you open up the DateTime.pdf, the date time value should  read 5:48:21 (what I set) and be immutable by you.  The first one is the form before the user changes the date.

Let us know if that works.

Duane
DateTime.pdf
DateTime_BeforeFilling.pdf
Reply all
Reply to author
Forward
0 new messages