Conditionally include static text in DOCX template for non-empty fields

Hello,

I need to be able to include static labels into a report for non-empty fields. Labels should not be included in a report if a field is empty. For example, ‘Genre:’ label should be included if ${Book.literatureType.name} is not empty, otherwise it should be omitted.

Thank you,
Dmitriy Melikov

Hello @dmelikov,

You can create a band with a groovy-script and format the output. Or you can fully form the text and transfer it to one tag, and if formatting is required, use the html formatter (Форматы значений полей - Платформа CUBA. Генератор отчётов).

Example:
Report templare:

Band (Dataset - groovy):

import com.haulmont.cuba.security.entity.Group

def groupId = params['group'].id

def group = dataManager.load(Group.class)
                       .query('select e from sec$Group e where e.id = :groupId')
                       .parameter('groupId', groupId)
                       .viewProperties(
                           'name',
                           'parent.name')
                       .one()

def result = "Name: ${group.name}"

if(group.parent != null) {
    result = [['name': "Name: ${group.name}",'parent':"Parent: ${group.parent.name}"]]
} else {
    result = [['name': "Name: ${group.name}"]]
}

return result

Result:

Report: Report.zip (11.0 КБ)

Regards,
Nikita

Hello Nikita,

Thank you for getting back to me.
I will follow your recommendation.

Best regards,
Dmitriy Melikov