Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Auto-Fill Date Field and Save

Avatar

Level 3

Hello,

I searched for a solution for this, but I am unable to find anything that will work for me and I am wondering if anyone can help.  I am trying to get a date in form auto-fill with the current date.  I have figured out that using the FormCalc forumla: $.rawValue = num2date(date().DateFmt(3)).  The problem I am facing is that the form saves with the current date, but when I save the form and reopen on a different day, the date changes.  Is there a way to lock the current date in the field when it is opened on a different day? 


I am also wondering if I can make the same sort of forumla for the current time.  I also need this to not change when it is opened on a different day.


I am learning Javascript slowly so bear with me on the responses


Justin

5 Replies

Avatar

Level 5

Hi Justin,

you could use the following script in the form ready event in javascript:

var sDate = new Date();

this.rawValue = util.printd("dd.mm.yyyy", sDate);

or

this.rawValue = util.printd("dd.mm.yyyy", new Date());

hen you need another dae format you can change this:

this.rawValue = util.printd("yyyy-mm-dd", new Date());

You could check if the field..if it's empty then insert a new date else do nothing.

if(this.rawValue == null)

{

       this.rawValue = util.printd("yyyy-mm-dd", new Date());

}else{}

Hope it will helps,

Mandy

Avatar

Level 3

Mandy,


Thank you for the reply.  I attempted to try out all the codes, but nothing seems to populate the date.  I am not sure if I am missing a step, but for some reason I cannot get it to work out.  Any additional thoughts?


Justin

Avatar

Level 5

Hi Justin,

please take a look here https://workspaces.acrobat.com/?d=iO0y3fy7lz3bdLbxkg2ktA

My english is not so good I hope I understand your first question right.

You could insert a screenshot from your pdf (hierarchy and scripting) and I take a look.

Kind regards Mandy

Avatar

Level 3

Mandy,


I tried to update the form without luck.  Can I get your email to email it to you?

Justin