Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is there a way to add dynamic variables to a function in a velocity user macro?

Alex Yasurek
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.
June 16, 2015

Hi,

So I am trying to use this function in a user macro I am creating: 

getContentInSpaceForAllLabels(int offset, int maxResults, String spaceKey, Label... labels)
(function doc page)

Problem is the part that says "Label... labels". The labels need to be added as separate variables it seems because I have not been able to get to work any other way. Right now I have the function working by using it like this:

#set($pages=$action.labelManager.getContentInSpaceForAllLabels(0, 99, "Spacekey", $label1, $label2, $label3))

This works fine if I know there will always be 3 labels but the problem is I don't know this until run time. I may need to add 2 labels or 6 labels to this function. 

Anyone know of a simple way to configure this to work with a dynamic set of labels?

 

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
childnode June 16, 2015

it's a simple java question, lmg.rtfm.fy

http://docs.oracle.com/javase/6/docs/technotes/guides/language/varargs.html

just syntactic sugar Label... labels is exactly the same as Label[] labels

 so your answer is: just pass an array at runtime

Alex Yasurek
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.
June 17, 2015

Hi, I tried that before and it doesn't seem to work. This is what I tried: #set($labellist= ["a", "b", "c"]) #set($pages=$action.labelManager.getContentInSpaceForAllLabels(0, 99, "Spacekey", $labellist)) When I revert it back to - #set($pages=$action.labelManager.getContentInSpaceForAllLabels(0, 99, "Spacekey", $label1, $label2, $label3)) - it works fine again.

Alex Yasurek
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.
June 17, 2015

I should also mentioned I tried making an array of labels but that just seemed to blow up confluence: #set($label1=$labelmanager.getLabel("a")) #set($label2=$labelmanager.getLabel("b")) #set($label3=$labelmanager.getLabel("c")) #set($labellist= [$label1, $label2, $label3]) #set($pages=$action.labelManager.getContentInSpaceForAllLabels(0, 99, "Spacekey", $labellist))

TAGS
AUG Leaders

Atlassian Community Events