Report - template with custom definition (groovy script)

Hi.

How can I receive the “report” and “rootBand” in the groovy script. Currently I reveive only “params” (I must load data manualy).

My script:


import com.haulmont.cuba.core.global.LoadContext;

import com.haulmont.cuba.core.global.AppBeans;
import com.test.entity.*;

def dataManager = AppBeans.get('cuba_DataManager');
def loadContext = LoadContext.create(DoCument.class).setId(<b>params</b>.entity.getId()).setView("document-edit");
def document = dataManager.load(loadContext);
    
return ...

Marcin

Hi Marcin,

You can use the “parentBand” parameter in the groovy script and receive the root with com.haulmont.yarg.structure.BandData#getParentBand.

As for the “report” parameter, it is not implemented now. Actually, a groovy script can be set for only one report.

Hi Olga,
My groovy script I use as custom template (not as report script).
I tried to write a class like in java

<b>public class </b>OpenTransReport <b>implements </b>CustomReport {

    @Override
    <b>public byte</b>&#91;&#93; createReport(Report report, BandData rootBand, Map<String, Object> params) {

but for groovy script, this not works (I receive Exception).

custom_template

What Exception do you receive, exactly?

Hi Olga,

Exception:
MissingMethodExceptionNoStack: No signature of method: OpenTransReport.main() is applicable for argument types: ([Ljava.lang.String;) values: [[]]
Possible solutions: wait(), wait(long), find(), any(), wait(long, int), each(groovy.lang.Closure)

Sample of custom template code:

import com.haulmont.yarg.formatters.CustomReport;
import com.haulmont.yarg.structure.BandData;
import com.haulmont.yarg.structure.Report;
import java.util.Map;

public class OpenTransReport implements CustomReport {

@Override
public byte&#91;&#93; createReport(Report report, BandData rootBand, Map<String, Object> params) {
        return "TEST".getBytes();
}

}

If I add main method, I receive java.lang.NullPointerException

Hi Marcin,
Try to write a groovy script without class definition.
The groovy script returns byte[].
But the groovy script has only one variable: “params”.
I think the better solution is using Java class which implements CustomReport. See example: [url=https://github.com/andreysubbotin/csvreport/blob/master/modules/core/src/com/company/csvreport/core/CsvReport.java]https://github.com/andreysubbotin/csvreport/blob/master/modules/core/src/com/company/csvreport/core/CsvReport.java[/url]
Thanks

Hi Andrey,

Currently I have groovy script without class.
I need an editable custom template so I chose groovy script.
I have a idea to write a custom template in java which execute a groovy script in same name as template code.

Thanks

Hi Olga,
I have a one doudt.How to do that YARG report generation.anyone please give me.And then how i adding custom template in parameter and formets inside.