Eval-data not working in reporting macros
Hi I'm having a problem with getting {eval-data} to work inside a reporting macro.
Free-standing the following works perfectly and produces the expected result "5":
However, this does not work:
The nested report produces a string like "2+3+0" inside an {eval-data} macro, but gives no result or error when being rendered. If I remove just the {eval-data} fields the expression is printed correctly, but naturally not evaluated.
I'm thinking the problem is related to {eval-data} being rendered before the inner report, and thus no valid expression is available to evaluate, but that should have resulted in an error from {eval-data} of which there are none. This leaves me puzzled.
I know that the new Reporting 3.2.0 has a Stats-supplier that could let me do this math, but we're still on Confluence 2.9 so that is unfortunately not an option yet.
If no solution exists using {eval-data} I'm prepared to make a custom macro to sum the numbers instead. I've experimented with this already by creating a {sum} macro that takes the expression as body, as shown below, but for some reasong this isn't working either due to an error in the Velocity code which I can't identify.
Please assist.
Free-standing the following works perfectly and produces the expected result "5":
{eval-data:Sum}2+3{eval-data}
However, this does not work:
{report-on:injected=true}
{report-table}
{content-reporter:space=@self|types=page|scope=Folk > children|labels=person}
{text-sort:page:title|order=ascending}
{content-reporter}
{report-column:title=Navn}{report-info:page:title|link=true}{report-column}
{report-column:title=Rolle}{report-info:data:Rolle}{report-column}
{report-column:title=Timeforbruk}{eval-data:Sum2}
{report-block}
{local-reporter:data:Timer}
{date-filter:data:Dato|minValue=%data:Start%|maxValue=%data:Stopp%|format=EEE MMM dd HH:mm:ss zzzz yyyy|required=true}
{local-reporter}
{report-body}{report-info:data:Antall}+{report-body}
{report-empty}0{report-empty}
{report-block}0{eval-data}
{report-column}
{report-empty}Ingen oppgaver.{report-empty}
{report-table}
{report-on}
The nested report produces a string like "2+3+0" inside an {eval-data} macro, but gives no result or error when being rendered. If I remove just the {eval-data} fields the expression is printed correctly, but naturally not evaluated.
I'm thinking the problem is related to {eval-data} being rendered before the inner report, and thus no valid expression is available to evaluate, but that should have resulted in an error from {eval-data} of which there are none. This leaves me puzzled.
I know that the new Reporting 3.2.0 has a Stats-supplier that could let me do this math, but we're still on Confluence 2.9 so that is unfortunately not an option yet.
If no solution exists using {eval-data} I'm prepared to make a custom macro to sum the numbers instead. I've experimented with this already by creating a {sum} macro that takes the expression as body, as shown below, but for some reasong this isn't working either due to an error in the Velocity code which I can't identify.
#set ($Integer = 0)
#set ($sum = 0)
#set ($numbers = $body.split(","))
#foreach ($string in $numbers)
#set ($sum = $sum+$Integer.parseInt($string))
#end
$sum
Please assist.
1
person has this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
-
Inappropriate?I can't say definitively why it's not working inside the report, but I do know that Scaffold macros will behave oddly when executed inside a Reporting macro, particularly if inside a report that is iterating over other pages. The {eval-data} will be being executed in the context of the other page, which may be causing some issues.
I'd stick with the user macro for the moment. Your macro actually worked perfect for me - as long as you didn't have any spaces between the ',' and the numbers. Here's a small modification that will trim any extra blank space:
#set ($Integer = 0)
#set ($sum = 0)
#set ($numbers = $body.split(","))
#foreach ($string in $numbers)
#set ($sum = $sum+$Integer.parseInt($string.trim()))
#end
$sum
Enjoy :) -
Inappropriate?Very strange. No wonder I couldn't pin down the bug :-)
All I'm getting is this error: Error formatting macro: sum: com.atlassian.core.exception.InfrastructureException: Error occurred rendering template content 2,5,7,0
Perhaps the custom macro is having the same troubles as the {eval-data}?
I’m confused
-
Inappropriate?Hmm. I just tried running it inside a report and it seems to be fine. Does it work outside the report?
What's your wiki markup now? -
Inappropriate?My markup is the exact same as I posted before, only with {sum} in place of {eval-data} (I changed the sum to split on "+").
I just tested it again, and the custom macro gives the exact same error both inside and outside a report, so the report is obviously not the problem.
I wonder what an InfrastructureException indicates... -
Inappropriate?Hmm. Make sure you have the correct setting for the 'body markup'. I've attached a screenshot of my User Macro definition.
-
Inappropriate?We have now upgraded to Confluence 3.0.2 and Reporting 3.2.0, but both of the above mentioned methods still give the same results, meaning nothing at all from eval-data and an infrastructure-exception from the custom sum-macro.
I've tested this on two unrelated confluence instances with the same results. Do you have some special settings in your instance that allows the user macro to perform operations usually denied?
I’m very puzzled
Loading Profile...



EMPLOYEE
