Jump to content
We've recently updated our Privacy Statement, available here ×

How to add user defined function in iReport 4.7.1?


mondhe.mayur
Go to solution Solved by Ankur Gupta,

Recommended Posts

Hii there..

I have made a jar file named ConvertToWord.jar

This jar file contains pkg1 package. Inside that package a class named ConvertToWord exists. This class has a function named fun2 which takes argument in double and converts it into character.

For example for input 7500.00 it will give output as seven thousand five hundred. Now I want to add this function to my report and want to convert a summation generated by report into characters.

this class file extends JRDefaultScriptlet.

For that I have added this jar file into a class path from netbeans IDE7.2.1 > Tools > Option > iReport > Classpath > Add Jar

After that in report inspector window I opend Scriptlets node which is having default scriptlet as REPORT.  In its property Scriplet class I changed to COnvertToWord.pkg1.ConvertToWord

Now in summary part of my report I added a text field and selected its Edit Expression option.

In that I edited this -------> $P{REPORT_SCRIPTLET}.fun2($V{Total})

Here $V{Total} is total of a column.

when I click on preview it doen't even run...

can any one here help me for this...

I have attached ConvertToWord.jar

A line of reply will be highly appriciated.

 

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi mondhe,

The problem which I see here is with the scriptlet class you changed.

After that in report inspector window I opend Scriptlets node which is having default scriptlet as REPORT.  In its property Scriplet class I changed to COnvertToWord.pkg1.ConvertToWord

 

Here the scriptlet class would simply be pkg1.ConvertToWord as the jar file is already present in the classpath so you need not mention the name of the jar.

 

Change this class definition and it would work fine.

If this answers your query please don't forget to mark the answer as correct.

 

Cheers,

Ankur

Link to comment
Share on other sites

  • Solution

Hi mondhe,

For me the above thing works, I am attaching a working copy of the file : 

In this I have used the scriptlet class of yours , in the details section  using one of the fields, and then  I have used the same class coverting a variable which contains the sum of feilds over the report , and as it is working could be used anywhere.

In order to get the JRXML attached working what you will need to do is

1. Import the jar Tools(in the iReport Menu bar )-----> Options ----- > Click on Claspath Tab ------> ADD Jar -----> choose the JAr file (I Think You missed this step You need to import the JAR file through iReport through the above described process,  no need of using netbeans for classpath setting use iReport only)

2. Then you must choose Sample Database in the datasource

3. Then next you need to activate the the sample database from Help(in the iReport Menu bar )---->Samples---->Run Sample Database

4. Then Run the  Report

 

Crosscheck each and every thing , but I think what you missed is setting the classpath in iReport.Refer to point 1

Hope that it helps.Find the attachments attached

Thanks,

Ankur 

Link to comment
Share on other sites

  • 1 year later...

Hi Ankur!

 

Can we display alert message using scriptlet in ireport?

I want to display standard alert message in between report execution in jasperserver.

is it possible using scriptlet or any other way?

 

A line of reply will be highly appriciated.

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