I'd like to show kind of a "queue" showing queue positions with a pocket query mySQL statemant in confluence, using an order by clause.

What I do is:

  1. Join a few tables in a select statement
  2. select entries by different criteria
  3. sort them in an order by clause

In mySQL workbench I can use a custom variable to get a first column in the query result, showing the row number:

SET @qposition:=0;
	(@qposition:=@qposition+1) AS 'Position',

which does not work when using it in the pocket query.

Is there any other option to show the row number (position) of the result set?

Currently I use the following template:

.re { background: #F8E0E6; }
.yel { background: #F5F6CE; }
.gre { background: #CED8F6; }
## @param colresizable:true 
<table class="pocketquery-table confluenceTable">
  #foreach ($column in $columns)
  #foreach ($row in $result)
    <tr class="
		##	#if($row.get("Tage seit letzter Aktualisierung") > 14)gre
		##	#end
			#if($row.get("Differenz zum Fertigstellungstermin") > 1 && $row.get("Differenz zum Fertigstellungstermin") < 3)yel
			#{elseif}($row.get("Differenz zum Fertigstellungstermin") >= 3)re
    #foreach ($column in $row)

I hope my question can be understood smile

Thanks an kind regards,


1 answer

1 accepted

1 vote
Answer accepted

Hi Phillip,

Thank you for using PocketQuery! If I understand correctly, you want to simply number the rows of the resulting table?

You could do that directly within the template using a variable in a similar way, than you are currently doing in the SQL query. For example, the following template adds an additional column with a row number (starting from 1):

#set($number = 1)   ## define row counter

<table class="confluenceTable stickyTableHeaders"><tbody>
		<th class="confluenceTh">Row number</th>   ## add additional header cell
		#foreach ($column in $columns)
		<th class="confluenceTh">$!column</th>
	#foreach ($row in $result)
		<td class="confluenceTd">$number</td>   ## add additional cell with row counter
		#set($number = $number+1)    ## increment row counter

		#foreach ($column in $row)
		<td class="confluenceTd">$!column</td>

Let me know, if this helps or if you have further questions!

Hi Carla,

many thanks for your immediate help. Works great and solved it for me.

BR Phillip

In addition to Carla's answer: if you simply need a loop variable, you can also use the implicit ("magic") variable $velocityCount. It's available in any #foreach loop and starts with 1.

Good Point, Felix!

Phillip, I'm glad I could help. If you're happy with PocketQuery, maybe leave a review at the marketplace? We would highly appreciate it.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


271 views 0 7
Read article

Atlassian User Groups

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!

Find my local user group

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

Groups near you