charlierutledge Posted March 20, 2009 Share Posted March 20, 2009 I am trying to use a variable in conjunction with a scriptlet. I am running into a couple problems:1. Nothing to do with the scriptlet, but I can't initialize the variable. I have a variable named TestString, class java.lang.String, Calculation = System, Reset type = None, Increment Type = none, Initial Value Expression = new String("TestVal"). When I try to run the report I get the following error:The initial value class in not compatible with the variable's class : TestStringWhat is wrong with the Initial Value Expression? From examples, "new String("TestVal")" seems like it should do the trick.2. Setting the variable within the scriptlet doesn't persist between detail rows. I have a Text Field in the detail section of the report with the following expression:$P{REPORT_SCRIPTLET}.TestFunction()TestFunction is declared as:public String TestFunction() throws JRScriptletException { String getString; GetString = (String)this.getVariableValue("TestString"); System.out.print("GetString before: " + GetString + "n"); // Always shows "GetString before: null" this.setVariableValue("TestString", "Testing"); GetString = (String)this.getVariableValue("TestString"); System.out.print("GetString after: " + GetString + "n"); // Always shows "GetString after: Testing" return GetString;}Every time TestFunction is invoked, it shows that the TestString variable null. It does not retain have been set to a value of "Testing" when the function was invoked for the previous row. By my understanding, the variable TestString should retain that value from row to row given the parameters it was set to (Calculation = System, Reset type = None, Increment Type = none). What am I doing wrong?I am using iReport 3.1.4, scriptlet is built using jasperreports-3.1.4.jarAny insight would beappreciated.Post Edited by Charles Rutledge at 03/20/09 23:28 Link to comment Share on other sites More sharing options...
charlierutledge Posted March 23, 2009 Author Share Posted March 23, 2009 I found the problem with the value of the variable resetting. Looks like I needed to declare the variable with Rest type = Report instead of None. That made it work.Still no clue what was causing the problem with the Initial Value Expression, but turns out I don't need it anyway. Link to comment Share on other sites More sharing options...
anachii86 Posted April 18, 2017 Share Posted April 18, 2017 In my custom scriptlet, in the callBeforeReportInit function I try to set variable's value, however after report has been generated I get null. I did what you wrote about Reset type = Report etc, but I still get the null. May be you can help me with this troubles. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now