You are not logged in.
Pages: 1
In Jasper Reports Server we had the ability to add custom functions for use in our reports, for example non-standard day of week calculations, and non-standard week-start-date calculations.
We had the ability to create our own jar files and add them into JRS in the WEB-INF/classes/jasperreports_extension.properties file like so:
# CMT Custom Function
net.sf.jasperreports.extension.registry.factory.functions=net.sf.jasperreports.functions.FunctionsRegistryFactory
net.sf.jasperreports.extension.functions.cmtcustomfunctions=cmt.customfunctions.CMTCustomFunctions
We could them use these functions in our report expressions.
How can we do this in ReportServer?
Many thanks for you help.
Last edited by ianef (2024-08-15 16:29:51)
Offline
Hi ianef,
In ReportServer, you can achieve similar functionality by adding custom functions through the use of custom JAR files, much like you did in JasperReports Server. The process involves a few steps:
1. Create the Custom Function JAR File
First, you need to create a Java class with your custom functions.
Compile the class into a JAR file.
2. Deploy the JAR to ReportServer
Place the JAR file into the WEB-INF/lib/ directory of your ReportServer installation.
This ensures that your custom functions are available to the JasperReports engine used by ReportServer.
Alternatively, you can place the JAR file in ReportServer's external configuration directory. This approach is recommended as it simplifies future upgrades by keeping your custom libraries separate from the core application files.
3. In JasperReports, you can use your custom functions directly in the report expressions by referencing the fully qualified class name (i.e., including the package) and method name.
You don’t need to register the custom functions globally like in JasperReports Server with the jasperreports_extension.properties file. Instead, you just reference the class directly in your JRXML.
With other words:
In the JRXML file, when you write an expression, use the fully qualified name of your custom function class and method. For example:
<![CDATA[ cmt.customfunctions.CMTCustomFunctions.calculateWeekStartDate($F{dateField}) ]]>
In this example, cmt.customfunctions.CMTCustomFunctions is the fully qualified class name, and calculateWeekStartDate is the method you want to use.
4. Add the Import Statement (Optional)
Optionally, if you have many expressions using the same custom functions, you can import your class in the JRXML header:
<import value="cmt.customfunctions.CMTCustomFunctions"/>
This allows you to call your functions in the report expressions without needing to use the fully qualified class name each time:
<![CDATA[ calculateWeekStartDate($F{dateField}) ]]>
5. Restart ReportServer to make sure the JAR is being loaded.
Regards,
Eduardo
Offline
Many thanks Eduardo. That is really good news, I think this is my last problem in getting ReportServer up and running.
I really like the class import parameter in the JRXML file, that will make everything very easy to implement.
Excellent! Thank you so much.
Offline
Hi Eduardo
There seems to be a problem with the <import /> tag, this doesn't seem to work. I've tried adding this to my report using the following variations but none of them work. I have to prefix all the methods in each expression with the full method class path in order for it to work.
<import value="cmt.rsfunctions.RSCustomFunctions"/>
<import value="cmt.rsfunctions.RSCustomFunctions.HELLO_WORD"/>
<import value="cmt.rsfunctions.*"/>
Whilst I can stop the reports from crashing by using the full class path, it's not a sustainable solution. When reports are edited in JasperSoft Studio the full class path of the method is not used. This means we have to remember to edit the source via a text editor every time we update any of the expressions. This is guaranteed to cause hassle and frustration.
I've created a custom function library and sample report using the example from TIBCO:
https://community.jaspersoft.com/knowle … -part-2-0/
Here are the library files and report:
https://x-act.co.uk/files/cmt.rsfunctions.jar
https://x-act.co.uk/files/SampleFunctionsReport.jrxml
The report very simple. If you remove the fully qualified prefix on any of the method calls it fails.
Secondly, despite it's simplicity, all this report displays in ReportServer is a blank page, it does not show the report content. There are no errors reported.
Last edited by ianef (2024-08-19 13:59:25)
Offline
Pages: 1