Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Show Current Date in Year Format (and now - 1, etc.)

Avatar

Former Community Member

Our form has some column headers that need to change each year, the headings are current year (2010) + previous 3 years.  Am trying to programatically add the titles to eliminate modifying the form just to change the year, but not finding how to accomplish, and was checking out some date samples found, but no success yet.  My question is 2 part - how/where do I put code, I don't need the user to enter anything, just want a column header.  This example below is where I copied the idea from a sample and tried to adjust, it's on the calculate event of a date/time field, and I get an error message that says 'the display pattern "date-{MM/DD]" is incompatible with the object's data format.  Define a compatible Display pattern.  This display pattern error is the 2nd part of the question.  How do I display only the 4 digit year?

year1.rawValue

= num2date(date(), "YYYY")

How do I accomplish this - am newbie on this!  Thank you very much!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I'd be happy to take a look at the form. stwalker.adobe@gmail.com

Steve

View solution in original post

4 Replies

Avatar

Former Community Member

1) I typically use a hidden field to capture the current date on the layout:ready event.

2) If year1 is a date object  your script is valid but you are probably missing the display pattern date{YYYY} on year1.

If year1 is a text field you could could capture current year in a hidden field as

// form1.page1.currentYear::ready:layout - (FormCalc, client)

$.rawValue = Num2Date(Date(), "YYYY")

where currentYear has the display pattern date{YYYY} and add

this.rawValue = form1.page1.currentYear.rawValue;

to the calculate event of year1.

Steve

Avatar

Former Community Member

Thank you, my field is a date field, though it's giving me the error I mentioned when I use that format.  I am totally new at this in LiveCycle so I'm not sure I'm putting the code in the right place, and not sure how to remove the error, maybe if I use your idea to bounce a text box off the date field and format the text box - it's all over my head at the moment, so I appreciate the help, thank you.

Avatar

Correct answer by
Former Community Member

I'd be happy to take a look at the form. stwalker.adobe@gmail.com

Steve

Avatar

Former Community Member

Thank you for your help, to share your solution, I had my script in the wrong place, it should have been in FormCalc calculate event, and I was not using case sensitive field or function names, and did not have my display pattern right, it should have been date{YYYY}

Corrected:

//  topmostSubform.Page5.Year1::calculate - (FormCalc, client)

$.rawValue = Num2Date(date(),"YYYY")
To get the other column headers, I subtract 365 or however many day equal the years I want to subtract from current year.
Example,
$.rawValue = Num2Date(date()-365,"YYYY")
I really appreciate your help, works nicely, thank you.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----