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

Populate Time Field based on check box

Avatar

Level 3

I'm trying to come up with a script to do the following:

if checkfield.rawValue = "1" (checked)

     timefield.rawValue = (current time)

if checkfield.rawValue = "0" (unchecked)

     timefield.rawValue = "null"

Any ideas or suggestions would be greatly appreciated.

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

here is a modified version. The BBS display of the script added extra chars that messed things up. I moved the code to the change event of the checkbox (I think it is nicer whne the user clicks to see the change as opposed to exiting the checkbox field). Th e validate message was coming up because you had a pattern on the field and the resulting time does not match that. I removed the pattern as well as turn off the validation script message.

Paul

View solution in original post

6 Replies

Avatar

Former Community Member

This FormCalc code will do what you ask:

if

(checkfield.rawValue == 1) then

     timefield.rawValue

= Num2Time(time())

else

     timefield.rawValue

= ""

endif

Paul

Avatar

Level 3

I'm getting an error with that script.

"Error:  Accessor "checkfield.rawValue" is unknown."

This error happens upon opening the form.

The FormCalc script is placed as an exit event on the checkfield.

I have a series of check boxes with a corresponding series of time fields.  Each time a check box is checked ( == "1" ), I need the corresponding time field to calculate the current time (thus logging the time each box is checked).

Any ideas?

Thanks.

Avatar

Former Community Member

Its easier to debug if I can see the form...can you post it?

Paul

Avatar

Level 3

I've copied the check and time fields onto a new form (as an example) and have placed the FormCalc script on the first checkbox only.

A different error is occurring now.  The script appears to be working, but every time I check the box a warning comes up stating the time field failed to validate.

Thanks for your assistance with this.  It is greatly appreciated.

Avatar

Correct answer by
Former Community Member

here is a modified version. The BBS display of the script added extra chars that messed things up. I moved the code to the change event of the checkbox (I think it is nicer whne the user clicks to see the change as opposed to exiting the checkbox field). Th e validate message was coming up because you had a pattern on the field and the resulting time does not match that. I removed the pattern as well as turn off the validation script message.

Paul

Avatar

Level 3

Many thanks Paul.

Once again your assistance has been invaluable.

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] ----