Updating Data Set query after parameter input in BIRT

孤者浪人 提交于 2019-12-24 05:12:41

问题


How can I change or update a data set's query after a parameter has been passed in BIRT report designing?

Detailing:

I've got a query that looks like this:

WHERE ? 

That parameter marker can hold different values, after user input parameter, it would look like this e.g.:

WHERE column_name = 1

or

WHERE column_name = 2

or even

WHERE column_name IN (1,2)

I created a Report Parameter(RP) for that Data Set Parameter(DSP) and after trying for hours, I couldn't get to change it.

I tried:

  • Creating all sorts of javascript expressions on both, RP and DSP
  • Creating a RP that would change the value of the first RP and back to previous step
  • Editing the Property Binding, though I couldn't figure it out how exactly it should be done. Just to make it clear, I'm designing a report and not integrating the runtime to an existing application. I hope this is clear enough, I'm still editing the question so if you need more information just let me know.

Thanks


回答1:


Assuming that you are on an Oracle DB (other systems may behave differently) you should be aware that a bind variable (in JDBC speech: the question mark) can replace a scalar value only, e.g. a string or a number.

But you want something like a list of numbers as input. Thus a bind variable won't help you in this case.

Probably the easiest way to achieve what you want is this:

In your query, write:

WHERE column_name in (1) -- $REPLACE_THIS$

Note that I am using a comment in the query as a marker. Then, in the query's beforeOpen event, modify the query text like this:

// construct a comma-separated string representation of your list
// based on your report parameter (exercise left to the reader)
// var replacement = my_to_sql_csv(params["my_report_parameter"].value);

// for demonstration use:
var replacement = "1,2";

// modify the `IN` expression inside the SQL
this.queryText = this.queryText.replaceAll("(1) -- $REPLACE_THIS$", "(" + replacement + ")";

That's it.



来源:https://stackoverflow.com/questions/28070809/updating-data-set-query-after-parameter-input-in-birt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!