Bug 211970 - Create report variables / report functions
Summary: Create report variables / report functions
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: 2.3.0   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: Future   Edit
Assignee: Helai CLA
QA Contact: Tianli Zhang CLA
URL:
Whiteboard:
Keywords: plan
Depends on:
Blocks:
 
Reported: 2007-12-05 03:44 EST by Erwan BODERE CLA
Modified: 2011-05-17 03:34 EDT (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erwan BODERE CLA 2007-12-05 03:44:47 EST
I want to create a report showing the annual evolution of the characteristics of certain entities. I want the user choose the base year (the upper bound of the period) and that the report calculates automatically the lower bound of the period.

So, I create a report parameter to input the base year value. When i create a data set, i want to add filters : upper bound and lower bound. The upper bound value comes from the report parameter and the lower bound value should be calculated :

------------------------------
lower_bound = param["upper_bound"] - period_size

if( lower_bound < min_year) { min_year } else { lower_bound }

------------------------------

I want to store 'period_size' and 'min_year' values in report variables, and then use this variables anywhere i want with the expression builder editor.

Another solution will be to create a report function to calculate the lower bound. This function should also be used in the expression builder editor. 

I use many times some personal functions (converting values, ...) in datasets filters, display and formatting values, ...

Personal report variables and functions should be very usefull. What do you think ?
Comment 1 Rick Lu CLA 2007-12-07 03:28:24 EST
Have you tried to define variables in BIRT scripts and event handler class features?
Comment 2 Erwan BODERE CLA 2007-12-07 09:14:25 EST
There is a lot of ways to create variables (computed columns, ...).

I only suggest to have access to personnal variables and functions in the "expression builder" window. It should be very usefull and more visual. Especially for functions : for example, if i want to use a personal converting function, i choose my personal function in a list of personnal functions and choose field(s) from the dataset.
Comment 3 Wenfeng Li CLA 2007-12-11 20:25:10 EST
It seems BIRT already allows report level personal variables and functions by including an external js file that have those functions. But they are NOT visible in the "expression builders"

Is there a way for model to parse the included js file and provide an API to return all the variables and functions in the included js file? If so, expression builder then can show them along with the data set fields?
Comment 4 Ivy Li CLA 2008-01-02 18:14:12 EST
If the variable is supposed to be visible for all the expressions that user write in the report, the variable should be defined at Report level. We have a structure called ConfigVariable under the report root node. This structure allow user to define the name and value pair of the variables. And should be visible for all the elements under this report design tree. But I just took a look from designer, seems they didn't expose this structure in the property editor. The expression builder should also provide the function to let user see all the variables deined in the ConfigVariable list. After this, maybe there are some work for DtE to do. Am not sure whether DtE suppport the expression to evalute the value from the configVariable.  
Comment 5 Rick Lu CLA 2008-01-03 01:47:21 EST
(In reply to comment #3)
> It seems BIRT already allows report level personal variables and functions by
> including an external js file that have those functions. But they are NOT
> visible in the "expression builders"
> 
> Is there a way for model to parse the included js file and provide an API to
> return all the variables and functions in the included js file? If so,
> expression builder then can show them along with the data set fields?
> 


Rhino is mainly used to run javascript. It has an internal tree representation. However, some classes are not public or some public classes are not documented. And this IR may change with the version increase.
Comment 6 Gary Xue CLA 2008-01-03 15:59:00 EST
I would discourage trying to use Rhino to parse any Javascript code to identify functions. as Rick noted Rhino does not expose public parser APIs. Our past experience with the use of internal parser classes have caused us pain.

I suggest the following approach to this enhancement:
(1) At the report level, provide Script-Function report elements. Each Function has a function name, a collection of parameters (note that since Javascript variables are untyped, the parameters will have just names), and a block of JS code provided by user.
(2) Expression editor will display all report-level script functions under a new category User Functions.
(3) Engine will execute all script function code during report.initialize event. This will ensure that all script functions are defined and are available to all report scripts.

Let's start with a UI mockup to demonstrate how this feature will work in BIRT report designer.
Comment 7 Wenfeng Li CLA 2010-02-09 17:25:01 EST
set to future until there is UI mock up so that we can estimate the completion milestone.