Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Generate random ID in User Macro

Brian Mendes
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 4, 2019

I've been using $action.dateFormatter.calendar.timeInMillis for a while now to create a random ID for some JS functions I call in my user macro but this doesn't seem to work anymore. 

I use the same macro serval times in a page therefor I have to be able to distinguish between them. The macro generates an form and an email depending on what is selected in the editor  (Installation request or Problem report). 

Is there an other way to generate a random ID? 

1 answer

0 votes
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2019

Yeah, it looks like those methods are depreciated. Here is one thought, there is this method in the general utils accessible via Velocity

------------------------------------

getRandomSubSet

public static <T> List<T> getRandomSubSet(List<T> list,
                                          int sizeOfSubset,
                                          Random random)

Returns a randomized subset of the list provided. If the size of the subset is larger than the list, the entire list is returned in a random order.

Parameters:
list - - the list to subset
sizeOfSubset - - the size of the subset to return
random - - the source of randomness
Returns:
a randomised subset of the list

------------------------------------

 

So create your list of some random set of IDs, then just select a subset of one element from your list randomly.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events