Jump to content
Changes to the Jaspersoft community edition download ×

carrying a field value to another row


dogmac

Recommended Posts

Hi,

 

I need to do a growth chart, with differences between each row.

 

eg

 

Code:

Services Growth
Jan 15 -
Feb 20 25%
Mar 30 33%

 

But I can't work out how to carry forward the services field value to the next row. I've tried setting a variable, but it is calculated at the start of each row, not the end, so I am always getting 0%. Is there a cunning way I can do this?

 

Thanks

 

Di

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

You can do this with a scriptlet. The sample scriplet below accepts an Integer value from the current row and returns the Integer value from the previous row, or zero if you are on the first row.

 

 

To use it you set your Integer TextField's expression to be $P{REPORT_SCRIPTLET}.getLastValue($F{ProtocolID})

 

 

 

Code:
import net.sf.jasperreports.engine.*;


public class yourprojectnameScriptlet extends it.businesslogic.ireport.IReportScriptlet {

public Integer myLastValue = new java.lang.Integer(0);

/** Creates a new instance of JRIreportDefaultScriptlet */
public yourprojectnameScriptlet() {

}

public Integer getLastValue(Integer nextValue) throws JRScriptletException
{
Integer i = myLastValue;
myLastValue = nextValue;

return i;

}


}

Post edited by: jmurray, at: 2007/07/04 23:43

Link to comment
Share on other sites

I spoke too soon!!

 

It worked beautifully within ireports, but as soon as I tried to call it via my webinterface, I started getting the following error:

 

java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getErrors()[Lorg/eclipse/jdt/core/compiler/IProblem;
17:15:33,953 ERROR [sTDERR] at net.sf.jasperreports.engine.design.JRJdtCompiler$2.acceptResult(JRJdtCompiler.java:389)
17:15:33,953 ERROR [sTDERR] at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:417)
17:15:33,953 ERROR [sTDERR] at net.sf.jasperreports.engine.design.JRJdtCompiler.compileUnits(JRJdtCompiler.java:463)

 

as soon as it tried to compile.

 

I'm assuming this is because it can't find the tools.jar.

 

I've put the tools.jar in my project, and added it to the build and to the application.xml. I check the tmp jar that is deployed and it is definitely there. I've tried putting it into my jboss classpath, and that makes no difference.

 

I can't find anything online that matches this, there are a few close ones, but all the ones I have attempted have failed.

 

Help!

 

Thankyou

 

Di

Link to comment
Share on other sites

The error message says that it can't find the getErrors() method within apache commons. This error message could be masking one or more other errors.

 

 

It looks like your classpath is not defined correctly or you are missing one of the commons*.jar files.

Link to comment
Share on other sites

Sorry to be completely picking your brain, and I know this one isn't directly ireports related, but still... HELP!

 

It was missing the commons.jci.core file, which I have now added, but it is still not actually finding it. I've added this to my project build path, the .build file and the .application file, and it is still not finding it.

 

From googling, I've come to the conclusion that I need to add something to my .project file in Eclipse, but I can't for the life of me work out what it would be. A maven connection maybe?

 

Has anyone had any experience with this?

 

Thankyou so much

 

Di

Link to comment
Share on other sites

  • 1 month later...

Hi all,

 

I was successful in creating a scriptlet showing the data for the last row - as well as creating a method to calculate the percentage change.

 

It work fine for one of my columns. But, I'm getting 10 values from my query, and I would need the percental deviation to the previous row for each of them.

Unfortunatly the above described method only works for one of my columns - if I add additional columns to hold the percental deviation for the other values, I get some kind of chaos figures, as the described method always stores the data of the last execution (which then leads to a in-row calculation).

 

 

Is there a way to really get the last value for a given field?

 

Thanks for your help!

 

Kai

Link to comment
Share on other sites

Whoever may be interested - here is my scriptlet code - sorry for my "bad" Java:

Code:

import net.sf.jasperreports.engine.*;


public class quarterlyStdReport_TableSubScriptlet extends it.businesslogic.ireport.IReportScriptlet{


public Integer myLastValue = new java.lang.Integer(0);

/** Creates a new instance of JRIreportDefaultScriptlet */
public quarterlyStdReport_TableSubScriptlet() {

}

public Integer getLastValue(Integer nextValue) throws JRScriptletException
{
Integer i = myLastValue;
myLastValue = nextValue;
return i;
}

public Double getPercentage(Integer nextValue) throws JRScriptletException
{
Double currentLine = new java.lang.Double(nextValue.doubleValue());
Integer i = myLastValue;
myLastValue = nextValue;
Double percentage = new java.lang.Double(0);
if (i != 0)
{
percentage = new java.lang.Double(((currentLine.doubleValue() - i.doubleValue()) / i.doubleValue()) *100);
}
else
{percentage = new java.lang.Double(0);}

return percentage;
}
Link to comment
Share on other sites

  • 1 month later...

Hi all,

 

is there a way to do the same without scriptlets?

It seems to be not possible to get the scriptlet into JasperServer (see http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=view&catid=10&id=30956

).

 

Would I be able to get the same when using a "simple" additional java class? Then I could get rid of the scriptlet ...

 

Thanks for any input!

 

Kai

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...