Dynamically Getting/Setting Report Parameters

I’m trying to build a generic window that allows users to select and configure reports to run.
I have a selector component that lists the available reports and sets the path on a Report Viewer component.
Now I’m trying to generate input components based on the parameters of the chosen report, and am having some difficulties getting the names and types of the dynamic properties available to me.

After reading this post I can get the list of dynamic props as a java.util.Treemap using getDynamicProps(), but I can’t seem to get/set the report parameters.

I can’t access it as a dict in jython:
props['Date'] returns a None

Nor directly through the property:
get('Date') returns a None

Though strangely, when trying put('Date', system.date.now()) I get a type mismatch since it’s expecting a DynamicPropertyDescriptor, not the type of the property… But if that’s the case, shouldn’t my attempts at reading the property yield that type even when the underlying parameter is unset?

Not sure if I’m going about this all wrong, but I need to get the names+types of report parameters and hopefully set them.

Try printing the .keySet() from the treemap to see what you really have. You may find it helpful to browse the JavaDoc for these methods and objects.

1 Like

Thank you for the prompt reply and helpful info, though it’s still not clear to me where I’m going wrong.

Here’s my logging code:

props = event.source.getDynamicProps() date = props[str('Date')] logger = system.util.getLogger("DEV") logger.info(str(props.keySet())) logger.info(str(date)) logger.info(str(date.getPropertyType())) logger.info(str(date.getPropertyValue()))

Which produces this output:

13:54:35.528 [AWT-EventQueue-2] INFO DEV - [Date, EndDate, StartDate] 13:54:35.529 [AWT-EventQueue-2] INFO DEV - Date 13:54:35.530 [AWT-EventQueue-2] INFO DEV - <type 'java.lang.String'>
and then errors…

I’m calling the above code from the propertyChange event script on the reportviewer, which only fires for the propertyName ‘reportPath’. Weirdly, I get the above output when I switch off from the report I’m concerned with (to an essentially blank one). I’d expect to see that log info when I switch onto the right report.

If you really have unindented code in a propertyChange script, remove it. There can be all kinds of weirdness if you don’t have all of your code nested in an appropriate
if event.propertyName == 'someName': code block.
And it is likely too soon after switching to a particular report to expect the custom properties to be established – that requires deserializing the template definition. Place your code in a separate button’s actionPerformed event so that you know it runs correctly. After that, you can automate further with system.util.invokeLater() to get an appropriate delay.

Meanwhile, show the error you get when getPropertyValue() fires. Consider just using the component’s getPropertyValue() method instead of the descriptor’s method once you have the name to look up.

1 Like

The propertyChange event code isn’t unindented and is under a similar conditional (“reportPath”). I mentioned that but should have put it in my code block for clarity. Sorry about that.

Firing the getProps code by a button does resolve that timing-related issue, and as a result getPropertyType does return the correct type now (Date whereas before it was String). I was also using getPropertyValue on the treemap descriptor typed value instead of getValue. :disappointed_relieved:

For completeness, here’s the error I got before:
AttributeError: 'NoneType' object has no attribute 'getPropertyType'

The resources you linked and timing insight fixed my problem, thank you Phil!

1 Like

I’m attempting to do the same thing as yourself… once you have the correct values in the treemap how did you shove it all back into the report and have the report update itself to reflect the new parameter values?

OK… never mind on this. I slept and figured it out. After setting the values call loadReport on the report viewer.