Forums

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

Using user macro parameters as integers

Yaacov Weingarten
Contributor
June 4, 2018

Hi,

I am trying to write a user macro that receives an integer as a parameter, and use it as an integer in a Velocity Range (for example) - I wrote a small macro -

## This is an example macro
## @noparam


#set ($maxndx = 20)
#set( $mindx = 12)
#foreach ($ndx in [$mindx..$maxndx])
 $ndx
#end

That works fine - printing out the numbers from 12 to 20

But when I add a parameter (whose type is integer) and use its value (as the upper limit):

## @Param uplimit:title=Item Limit|type=int|desc=maximum number|default=25
#set ($maxndx = $paramuplimit)

The foreach statement doesn't seem to execute - there is no output.

I get similar phenomena when I try to use if-statments comparing an integer to a parameter value.

So how do I use integers as parameters to a User Macro?

Thanx

2 answers

1 accepted

1 vote
Answer accepted
Davin Studer
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 4, 2018

There is a trick to this.

#set($paramuplimit = $generalUtil.convertToInteger("$paramuplimit"))
Yaacov Weingarten
Contributor
June 4, 2018

Thanx - that seems to work - are there similar converters to change a date (taken from a page - for example the creation date) into an integer?

Davin Studer
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 5, 2018

When you say change date into an integer do you want it in epoch time? If so, what do you want to accomplish with it?

Yaacov Weingarten
Contributor
June 5, 2018

Hi,

Yes, the intention was to change to Epoch time, but I found the answer in the meantime - using the Date.getTime() method. The purpose was to compare two times, which I accomplished using the before/after methods.

Thanx for the reply.

0 votes
Erhan Baz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2025

The latest version of VelocityUtil class doesn't include the convertToInteger() method, so please try the below code snippet to convert string values to integer:

#set ($Integer = 0)
#set ($paramuplimit=$Integer.parseInt($paramuplimit))

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events