Using this guide https://wiki.openmrs.org/display/docs/Text+Template+Renderer+Groovy I would want to display age in years and months. I am able to display age using $data.person.age (where person is my parameter) but I cannot use fullYears or fullMonthsSinceLastBirthday. It fails with
Caused by: groovy.lang.MissingPropertyException: No such property: fullYears for class: java.lang.Integer
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
@sthaiya if you look at that guide you linked to, it specifies that to use the “fullYears” or “fullMonthsSinceLastBirthday” properties, you have to be operating on an “Age” object. This would be if you put a column of type Age into your dataset and referenced it like $data.age. But if you are referencing the age property of the Person object (which you are doing when you say $data.person.age), this is an Integer.
I think this error is because you have not defined a value for age yet? Did you check on that? Then try $data.age.fullYears and $data.age.fullMonthsSinceLastBirthday
This error usually comes when you misspell a variable name or else try to call variables you haven’t defined.
Yeah given the information you have provided, it looks to me that the problem lies in $data.age being null. Did you try printing $data.person? Does it include the age? Is it null?
@sthaiya, it takes a lot of trial and error to get right unfortunately, and it’s certainly possible that we need to improve our groovy handling. I created a simple report on the demo server that I was able to get working with some less elegant syntax. I’m sure it could be improved. See: