Jump to content
Changes to the Jaspersoft community edition download ×

Initialize a variable depend on value of another variable


ajith.devendra

Recommended Posts

 



I have two variables



 



  1. TotalPcs
  2. ROW_COUNT


 



I want to initialize ROW_COUNT to zero if  the variable $V{TotalPcs}>100



 



Variable ROW_COUNT is defined as below   and It’s having an expression , but expression doesn’t initialize the ROW_COUNT .. It continues increasing by one .



 



Would you pls helpw me on this



 



Name = ROW_COUNT



Calculation =  No Calculation function



Expression = (($V{TotalPcs})>100) ? 0 :(new Integer($V{ROW_COUNT}.intValue() + 1))



Increment Type = None



Reset type = Report



 



Rgds



Ajith


Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Quite an interesting one. 
I tried a couple of combinations with create another variable and playing around with the Calculation set type, the increment set type and the Reset set type. 
Could not get the result you desired. 
The initial value expression would initialize based on the value you want, but that only gets executed as many times based on your increment and reset type and there is not expression to be use to manage this.

You have 2 options that I could think of:
1) To write a custom.jar that has a method that you can instantiate as a variable or in the text field box, where you pass the report count and your method return the last 2 number of the number. 
So if 10 return 10 if 99 return 99 when passed 100 return 100. 
110 it will return 10 
1110 it will return 10 
2000 would be 100
etc. 
You will have to get the logic right, but that is up to you. 

Option 2

Create a dummygroup in my case Group1. You can just add header. Make it 1 px in size.

Create new variable called ‘variable_1’ in my setup.
value class ; java.lang.Integer
calculation ; Count
Expression ; $V{REPORT_COUNT} != 0 ? 1 : 0
Initial value Expression ; 0
Increment type ; None
Reset type ; [Group] Group1

Then select the Group1 Header and in the Expression use
$V{Variable_1} == 100

So now your variable_1 will increment to 100 and then reset type is Group, so variable_1 will be reset to 0.
So $V{REPORT_COUNT} will continue with the standard row count, but variable_1 will count to 100 and reset to 0 and then start to count to 100 again.

Best of luck.
If anyone out there with better idea, please share.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...