Home
Analytics
Problem accessing data in event onFetch
unknown
Hello,
I'm using a data set that has the following columns: nombre, min_val, max_val and total. I'm trying to create a global variable as follows:
try {
var min=row.min_value;
var max=row.max_value;
reportContext.setPersistentGlobalVariable("min_val",min);
reportContext.setPersistentGlobalVariable("max_val",max);
} catch (error) {
}
This give me a error (see document attached)
However when I use hard data, no errors occur. For example:
try {
reportContext.setPersistentGlobalVariable("min_val","3");
reportContext.setPersistentGlobalVariable("max_val","6");
} catch (error) {
}
This indicates that the error is in the time of read the data. What is wrong? How do i get the value of a column in the onFetch() event?
Find more posts tagged with
Comments
mwilliams
Hi jnovat,
This is probably just a typo, but the first thing that stands out to me is that you say your columns are min_val and max_val, but you grab them as row.min_value and row.max_value. Let me know.
Migrateduser
Hello Michael,
Thanks for your reply,
I was wrong at the time of writing the query in the forum. In the project, I get the values as follows:
var min=row.min_val;
var max=row.max_val;
But already I solved the problem, the error was at the time of assigning values to the global variable. The final script is:
try {
var min=row.min_val;
var max=row.max_val;
reportContext.setPersistentGlobalVariable("min_val",new String(min));
reportContext.setPersistentGlobalVariable("max_val",new String(max));
} catch (error) {
}
Thanks.
mwilliams
jnovat,
That was going to be my next suggestion if your field was not of type string, you'd need to pass it into the global variable as a string. Glad you found the solution!
Migrateduser
Hello Michael,
I have a problem going from design environment (Eclipse-BIRT Report Designer) to the production environment (BIRT Runtime).
Everything works correctly in the designer (preview), but over the production environment happens the same scenario described above (when I use hard data, no errors occur)
attached the log of Birt Runtime and images with the two different results.
What can be causing this problem? Does it require some consideration or configuration additional?
I hope you can help me. Thanks in advance
mwilliams
jnovat,
Can you post the script from your chart, so I can see exactly what you have? The problem comes with line 41 in the chart script. Thanks.
Migrateduser
Hello Michael,
I have ordered some lines of script, the line 41 is now the line 39. Apparently the error occurs because can be not retrieve a global variable, but using hard data the problem no occurs (see the file "Script - Data Set - onFetch.txt").
I attached the scripts and log. The strange thing is that at design time (preview in eclipse) works correctly.
Thanks.
mwilliams
If you run the report with "run" or "preview" in the URL instead of "frameset", what happens?
Also, what does your data in your dataSet look like?
Migrateduser
Hello Michael,
With "preview report" it's ok. With "run report" occurs the same error that in "Birt Runtime" (Can't find method org.eclipse.birt.chart.model.data.impl.NumberDataElementImpl.create(null). at line 39 of chart script:''). See images attached.
I use the same data set for the table and the chart. I attached image of the result of the data set.
Note: With hard data working properly in all cases.
mwilliams
jnovat,
Sorry, I meant when you use the deployed viewer. Changing "frameset" in your URL to "preview" and to "run", what does it do?
Migrateduser
Hello Michael,
In both cases can be see the complete report (Chart and Table). i attached the respective images.
This means that "Birt runtime" needs some additional configuration?
Thanks in advance
mwilliams
jnovat,
What version of BIRT are you using? I'll do some testing using the data from your last post in a csv file.
Migrateduser
Hello Michael,
I am working with BIRT 2.5.2. Also I am testing other similar examples (one use a text file as data source) and not ocurr the problem.
Also i tested with BIRT Runtime 2.3.2.2 but ocurr the same problem.
Thanks.
mwilliams
jnovat,
Try one more thing for me real quick. Put a check for null before you grab your row values. Something like:
if (row.min_value != null && row.max_value !=null){
var min = row.min_value;
var max = row.max_value;
}
Let me know if that changes anything.
Migrateduser
Hello Michael,
Even adding the condition to validate the not null values, the problem persists.
However, I think have found the cause of the problem: the problem described occurs when, in the database, the max_val and min_val fields are numeric type, but the problem is solved when the fields are of type string.
With the fields defined as strings, the final script looks this:
try {
var min=row.min_val;
var max=row.max_val;
reportContext.setPersistentGlobalVariable("min_val",min);
reportContext.setPersistentGlobalVariable("max_val",max);
} catch (error) {
isRuntime = false;
}
However, this 'solution' has one drawback: by definition the fields that represent upper and lower limits are numeric type, not strings.
How could solve this drawback?
Thanks
mwilliams
jnovat,
After you've retrieved the PGV when you're getting ready to use it, you can parse it into an integer with the parseInt() function.
Migrateduser
Hello Michael,
That would be an alternative for working with numeric values in the script, keeping the fields defined as a string in the database. The correct thing would be to define the fields as numeric and convert to string in the script (eg with new String (value)) but when I work in this way ocurr the error described above.
Still do not understand why the error occurs but at least I have a temporary solution.
However, this case has helped me to see that I have to review more information about script event for now and later about java event. Could you recommend some books?
Thanks.
mwilliams
jnovat,
When you convert the value from the database integer to a string, try using variableName.toString() instead. See if that works.