Basically I want to know if there's a way to pull in a randomly generated number. I know I can do it in JS, just wondering if there's a way of doing it in Velocity.
It's funny. I forgot I posted this and then came back to the boards to search for answer and lo and behold, this is the best answer.
The random number method that was mentioned below didn't translate to anything but this method works.
The only thing to note is that you can only use it once per User Macro call (or so it seems). So if, like me, you're using this for IDs then you'll have to consider if this right for you. However, it works for me because I am only calling it once per macro (and then calling that macro several times in a page).
heh, since then I found a way to generate random numbers in a VM file with the MathTool class.
Add the org.apache.velocity.tools.generic.MathTool class to the Velocity context -- instructions are here (you'll need to modify the XML file to get the Math class rather than the Sorter that the instructions use): https://answers.atlassian.com/questions/62575/use-of-velocity-generic-tools-in-a-page-decorator
ah, in a macro I'm afraid that can't be done by default. Bellow is a link to the context which are provied in the user macro creation process.
And unfortunatley, the Math class is not among them. The only way this could be done is if we overrode the class that creates context by defualt in Confluence and added the math class...which I am not sure how to do myself
I've used this approach in several user macros to help make unique names for elements:
It generates a number with between 8 and 10 digits which appears to be random. The getRandom() method for the Action object was deprecated some time ago according to the documentation, but it does not mention the "random()" method.
Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time! We're looking for people to participate in a remote 1-hr workshop...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs