Skip to main content

This chapter extends the training course with a reporting scenario. The goal is not to cover every JasperReports feature, but to walk through the normal ADITO workflow once from end to end.

Task

Create a report for the Organisation context that opens in its own report view and lists:

  • the company name,
  • the customer code,
  • the current date in the report header.

The report should be opened from an action and rendered in a dedicated Report ViewTemplate.

tip

Before starting, read the feature documentation:


Solution

1. Create the report design

Create a new report, for example OrganisationReport_report.

Add:

  • two fields: ORGNAME, CUSTOMERCODE
  • one parameter: date

Then place the parameter in the page header and the two fields in the detail area.

2. Create the report data field

Create an EntityField in Organisation_entity, for example OrganisationReportData.

Its valueProcess should:

  • create the report object,
  • fill the parameter date,
  • query the organisation data,
  • map the data to the report fields,
  • return the generated report payload.

Example:

import { datetime, result } from "@aditosoftware/jdito-types";
import { newSelect } from "SqlBuilder_lib";
import { Report, ReportData } from "Report_lib";

const report = new Report("OrganisationReport_report");
const fields = ["ORGNAME", "CUSTOMERCODE"];
const reportData = new ReportData(fields);

const params = {};
params.date = datetime.toDate(datetime.date(), "dd.MM.yyyy");
report.addReportParams(params);

const data = newSelect("NAME, CUSTOMERCODE")
.from("ORGANISATION")
.table();

reportData.add(data);
report.setReportData(reportData);

result.string(report.exportReport()[1]);
tip

Keep the field names in the Jasper report and in ReportData identical and in the same order as the SQL result.

3. Create the report view

Create a new view such as OrganisationReport_view and add the Report ViewTemplate.

Configure:

  • entityField = #ENTITY
  • reportData = OrganisationReportData

See also: Report ViewTemplate

4. Open the report from an action

Create or extend an action so it opens the report view through neon.openContextWithRecipe(...).

Example:

import { neon, neonFilter, vars } from "@aditosoftware/jdito-types";

const recipe = neonFilter
.createEntityRecordsRecipeBuilder()
.parameters({
OrganisationReportData_param: true,
})
.uidsIncludelist([vars.get("$sys.uid")])
.toString();

neon.openContextWithRecipe(
"Organisation",
"OrganisationReport_view",
recipe,
neon.OPERATINGSTATE_VIEW,
null,
true
);

The recipe parameter is useful because the report field can use it as a guard and generate the report only when the report view is actually opened.

5. Optional next step

Once the basic report works, extend it with one of the advanced topics:

  • a Group Header per organisation,
  • a subreport for communication data,
  • a logo parameter such as adito.image.companyLogo.

Those patterns are covered in Advanced Reporting.