Reports Addon: Jasper Reports - Entity View

Hi Guys,

I am trying to generate a Jasper Report for an Invoice entity of mine.

Is there a way to change the view of the entity when it is selected?

What I have tried is: (will show photos)

  1. Making the Invoice a required selection parameter.

Inv 1

  1. Adding the invoice as a band so I can set the view:

inv 2

  1. Adding another band of groovy type to extract the values from the invoice entity

inv 3

If you look at the third picture. I am trying to get i.e. invoice.contract.account.name

It does work, however the report creates two pages, one with null data and one with the correct data.
See attached PDF of the output I am gettingBlank_A4.pdf (11.8 KB)

Any help much appreciated :slight_smile:

This seems to work:

But curious as to whether or not it is the right approach… Or if there is a simpler way…

inv 4

import com.haulmont.cuba.core.global.AppBeans

def persistence = AppBeans.get('cuba_Persistence')
def tx = persistence.createTransaction()
def result = []
try {

  def em = persistence.getEntityManager()
  def invoice = em.reload(params['invoice'], 'invoice-report-view')
 
  result.add([
  //invoice
  'invoice_total': invoice.total, 'invoice_number': invoice.invoiceNumber, 'invoice_id': invoice.id,

  //account
  'account_name': invoice.contract.account.name, 'account_number': invoice.contract.account.accountNumber])

} finally {
  tx.end()
}
return result

Hi,
Yes, you are using the expected approach - just reload the entity in a Groovy band.

The only note: you are using low-level API with Persistence and EntityManager where it’s not necessary.
The better way is to use DataManager (use DataManager.reload(entity, viewName) method).

Awesome, thanks Alex :slight_smile:

A couple more questions if you don’t mind…

  1. Can you add a second band that supplies fields to the Jasper Report? I have tried this but the report does not recognize the fields in subsequent bands.
  2. If so, is is possible to use the parameters (fields) from a higher order band in a lower band query?
  3. Is it only possible to use groovy dataset types to send to the report? Actually I suppose that is obvious as the report wouldn’t know about e.g. my Invoice.class - or can you send it as an object or something? i.e. can you send entities, sql, jpql etc to the JR?

Hello @daryn,

You can create several bands from the Root band, but nested bands are not supported

Documentation: JasperReports Template - CUBA Platform. Report Generator

Example with several bands: Report.zip (16.5 КБ)

About data types, you can only use data types that are known to Jasper reports.

Regards,
Nikita