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

RE:Form Automatic Numbering

Avatar

Level 2

HAY GUYS

I FOUND THIS CODE FOR GENERATING AUTOMATIC NUMBER AT ANY SPECIFIED  FIELD

POSTED BY MR.JONO MOORE

______________________________

MY QUESTION IS,

CAN I MAKE A BUTTON THAT ABLE TO REFRESH THAT CODE IN THE FIELD

SO I CAN GENERATE A NEW NUMBER EVERY TIME I PRESS THAT BUTTON ?

THEX ALOT ,,,

1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi,

Please note SHOUTING does not help.

Using the code above you could easily modify that to generate a number on a button click but removing the if from the code and placing this on a button click and assigning it to a field;

var d = new Date();

fieldName.rawValue = Math.floor (d/1000);

however as John stated this does not actually give you a random number as it relies on a date and could in theory result in the same number at some point so I would use

fieldName.rawValue = Math.floor(Math.random()*11); // this would give a random number between 0 and 10, if you want it in a different limit change 11 to something else.

Hope this helps

Malcolm

View solution in original post

1 Reply

Avatar

Correct answer by
Level 5

Hi,

Please note SHOUTING does not help.

Using the code above you could easily modify that to generate a number on a button click but removing the if from the code and placing this on a button click and assigning it to a field;

var d = new Date();

fieldName.rawValue = Math.floor (d/1000);

however as John stated this does not actually give you a random number as it relies on a date and could in theory result in the same number at some point so I would use

fieldName.rawValue = Math.floor(Math.random()*11); // this would give a random number between 0 and 10, if you want it in a different limit change 11 to something else.

Hope this helps

Malcolm