-2

I am working with my company's project. It uses Java Spring and Jaspersoft ireport 3.7.6 to print report.

I want to modify an exist report form (file jrxml). I want to sum a variable of 2 columns.

Data of these columns like

0/2/3/0

0/2/3/0=5

0/0/0/1

0/0/0/1=1

I have to calculate total of numbers which is behind '='.

I followed the solution in How to sum all values in a column in Jaspersoft iReport Designer?

I created a "GRAND_TOTAL" variable with caculation: "Sum", Class: "java.lang.Integer", resetType:"Report", incrementType:"none"

I added this condition to variableExpression

new Integer(($F{FullQty}.contains("=")) ? (Integer.valueOf($F{FullQty}.split("=")[1]).intValue() + Integer.valueOf($F{EmptyQty}.split("=")[1]).intValue() ) : (0))

When I print report, it shows error :

net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :

1. Variable not found : GRAND_TOTAL

Please help me!

Alex K
  • 22,315
  • 19
  • 108
  • 236
Tri
  • 1
  • 2
  • 1
    You need pass full jrxml, maybe you have defined the variabile in main report but are trying to use it in a subdataset. – Petter Friberg Jan 22 '21 at 10:21
  • @PetterFriberg thanks for your comment! But I think I can't share jrxml because it is belongs to my company's project. However, this jrxml doesn't use subdataset. After data is selected, they are converted to xml. Then, it is passed to jrxml report form to generate report. – Tri Jan 25 '21 at 01:47
  • create a [mcve] hence do a new report (with similar structure) but only related to this problem. Without this it's impossibile to help you since we would need a crystal ball – Petter Friberg Jan 25 '21 at 13:39
  • thank you so much! But I found the solution. Actually, this project use dynamic report, so I have to declare the variable in java code too. – Tri Jan 26 '21 at 03:56

1 Answers1

-1

I found the solution! My company's project use dynamic report. Therefore, I have to use fastReportBuilder to add variable in java code.

Tri
  • 1
  • 2