How do I use Calculated fields (Transient fields) in a report?

I created a report defining a Dataset type of JPQL.
This JPQL select statement has a Transient field named “calculatedNoOfSamples” in it.
Now when I try to run the report I get an error:
The state field path ‘j.calculatedNoOfSamples’ cannot be resolved to a valid type.

How do I use a Transient field in my report ?

Use groovy band and dataManager for load list of entity with transient fields.

Thank you Andrey

The following Groovy script works:

import com.company.lms.entity.Sample

def result = []
def job = params['job']
def samples = dataManager.load(Sample.class).query("select s from lms_Sample s where s.job = :job").parameter("job", job).view("sample-browse-view").list()

for (Sample sample : samples) {
result.add(['sampleID': sample.sampleID,
'sampleType': sample.sampleType,
'sampleMatrixCode': sample.sampleMatrix.code,
'collectionDateTime': sample.collectionDateTime,
'calculatedParameters': sample.calculatedParameters,
'calculatedNoOfContainers': sample.calculatedNoOfContainers,
'calculatedQEHLLabNos': sample.calculatedQEHLLabNos,
'sampleDescription': sample.sampleDescription,
'specialInstructions': sample.specialInstructions
])
}

return result

NOTE: In the above code, you will see where I used 3 transient attributes (aka calculated fields).

1 Like