Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

any way to have the current date pop up?

Avatar

Former Community Member

Hi -

I have a request form to create.  Pretty simple actually.

Halfway down the form I hve to put the following, where [ ] represents data input by user.

"This document has been open for [ ] days as of [ ]."

We want the user to type in a number from [1] to [99] (days open) and have the 'as of' [ ] be 'today's date' which would actually be the date of the filling out of this form.

So I created a table with 4 columns but it's not working right.

Any ideas?

The only other major item is an expandable comments section at the end. Shouldn't affect the information above.

Thanks for any help!

Marla

1 Accepted Solution

Avatar

Correct answer by
Level 10

Yup just rearrange the date pattern in the script to what you need, so the FormCalc version "YYYY-MM-DD" would become "DDMMMYY" or in JavaScript the "yyyy/mm/dd" would become "ddmmmyy".

And if you need the month in upper case you need to change the date line in the script a bit:

FormCalc: $ = Upper(Num2Date(Date(), "DDMMMYY"))

JavaScript: this.rawValue = util.printd("ddmmmyy", d).toUpperCase();

View solution in original post

3 Replies

Avatar

Level 10

On the Initialize event of the field you can put the following script - make sure the script editor is set for FormCalc:

if (HasValue($)) then

$ = $

else

$ = Num2Date(Date(), "YYYY-MM-DD")

endif

Or if you prefer JavaScript:

if (this.rawValue == null)

{

     var d = new Date();

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

}

else

{

     this.rawValue = rawValue;

}

The if statement will stop the date from changing if the form is saved and re-opened another day.

Avatar

Former Community Member

Hi Jono,

thanks, that does work.

New question:

1) How can I get the date field to look like this:      15APR11?

Is there a way to structure the code to do this?

Thanks!

Avatar

Correct answer by
Level 10

Yup just rearrange the date pattern in the script to what you need, so the FormCalc version "YYYY-MM-DD" would become "DDMMMYY" or in JavaScript the "yyyy/mm/dd" would become "ddmmmyy".

And if you need the month in upper case you need to change the date line in the script a bit:

FormCalc: $ = Upper(Num2Date(Date(), "DDMMMYY"))

JavaScript: this.rawValue = util.printd("ddmmmyy", d).toUpperCase();