Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass parameter when trigger .jrxml using python. #146

Open
que-m opened this issue Aug 28, 2023 · 2 comments
Open

Pass parameter when trigger .jrxml using python. #146

que-m opened this issue Aug 28, 2023 · 2 comments

Comments

@que-m
Copy link

que-m commented Aug 28, 2023

Right now i generate JasperReport using dynamic parameter, which we need to pass the parameter before run the file inside JasperSoft.
Therefore my current use case, i want to get the variable date using python, and pass the variable into the file before run the file inside python.

/> </field> </subDataset> <parameter name="dateFilter" class="java.util.Date"/> <parameter name="Parameter1" class="java.lang.String"/> <queryString> <![CDATA[select * from sampleData where created_at >= $P{dateFilter} ]]>

how i can declare the variable "dateFilter" in python and pass the parameter into the script?
and is there any documentation how to run the jasper file with parameter using python.

thank you

@jadsonbr
Copy link
Collaborator

No support for type java.util.Date passed as a parameter by the library. I advise passing it as a string and performing the conversion within the report until we implement typing for Date and DateTime

@jadsonbr
Copy link
Collaborator

@que-m

We have released version 2.1.4, which implements data typing for parameters sent to the reports. Please try using the new version and let us know about your experience.

Here's the link to the example: link

To find out the supported types up to this moment, access: Link

How to use:

import os
from pyreportjasper import PyReportJasper

def report_with_params():
    try:
        RESOURCES_DIR = os.path.abspath(os.path.dirname(__file__))
        REPORTS_DIR = os.path.abspath(os.path.dirname(__file__))
        input_file = os.path.join(REPORTS_DIR, "myteste2", "params.jrxml")
        output_file = os.path.join(REPORTS_DIR, "myteste2",  "output_file")

        pyreportjasper = PyReportJasper()
        pyreportjasper.config(
            input_file,
            output_file,
            output_formats=["pdf"],
            parameters={
                'myString': {
                    'value': 'TESTE STRING VALUE', 
                    'type': pyreportjasper.TypeJava.String
                },
                'myInt': {
                    'value': 1, 
                    'type': pyreportjasper.TypeJava.Integer
                },
                'myDate': {
                    'value': '24-02-2024', 
                    'type': pyreportjasper.TypeJava.Date, 
                    'format_input': 'dd-MM-yyyy'
                },
            }
        )
        pyreportjasper.process_report()
        print("Result is the file below.")
        print(output_file + ".pdf")
    except Exception as e:
        print(f"Error occurred: {e}")


report_with_params()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants