Report Parameter Passing

I’m building a report with an html/css document (pre existing document formats) and I cannot figure out how to pass a parameter into my document. I found through this Forum Post that I should be using a new band and making a groovy script to include my parameter ‘date’

return [[
'report_date' : params['date'],    
    ]]

But from there I cannot figure out how to put it into my FreeMarker template from there. The ai recommended I just pass it as ${date} into my template, but that just passes an empty string and not the parameter.

Thank you for the help.

Oran

Hi, @oran

Firstly, it is required to add a report input parameter with the date alias (see docs).

You can use the Root band to to get a input parameter value without adding an additional band. To do that, use the following expression: Root.fields.<inputParameterAlias> expression, where <inputParameterAlias> - a report input parameter alias.

Example:

<!doctype html>
<html>
  <head></head>
  <body>
     <#assign reportDate = Root.fields.date/>
     <p>Date: ${reportDate}</p>
  </body>
 
</html>

More information about HTML templates is described in docs.

Regards,
Maria.

1 Like

Thank you so much!

Context for anyone else approaching from my lower level of understanding.

  1. Define the parameter in the Parameters page of the report
  2. Parameters no longer have to be declared into a data band as it appeared in my last post and in many code examples on Apache Freemarker forums. This really got me confused, but it is no longer necessary atleast in the Jmix implementation.
  3. Parameters are considered fields of the Root band so they can be accessed in the same way as other fields in other bands you just use “Root.fields” instead of “Root.bands”
  4. The above example works perfectly, just remember that some data types have to be converted to a string, so in the above example I used <#assign reportDate = Root.fields.date/> and then insterted it into my template with ${reportDate?string("MM/dd/yyyy")}. Keep this in mind as most of these variables will not allready be of type string and can cause confusing looking errors.

Thank you again Maria that was exactly the context I needed and a perfect working example!

Thank you,
Oran