问题
i'm having trouble running a birt report via web. The report behaves as expected when running in html, but some scripts are not working properly via web viewer. I've got this script running on the "initialize" phase of the report (i know that a lot of the lines are not neccessary, just want be sure I got rid of any possible scripting syntax errors):
var inc_number;
var inc_number_old;
var contador;
var grupo;
var proveedor;
var contador_no_encaminadas;
var contador_encaminadas;
var contador_cerradas;
var estado;
var cliente_nombre;
var cliente_apellido;
contador = 0;
contador_no_encaminadas = 0;
contador_encaminadas = 0;
contador_cerradas = 0;
inc_number_old = 0;
And then i've got another little script running in a table row, with onRender triggering:
inc_number = row["Incident Number"];
grupo = row["Assigned Group"];
proveedor = row["Vendor Name"];
estado = row["Status"];
cliente_nombre = row["First Name"];
cliente_apellido = row["Last Name"];
if (inc_number != inc_number_old){
contador++;
if (proveedor != null && grupo != "SIGMA")
contador_encaminadas++;
if ((proveedor == null || proveedor == "") && (grupo == "SIGMA") && (estado != "Resolved" && estado != "Closed"))
contador_no_encaminadas++;
if (estado == "Resolved" || estado == "Closed")
contador_cerradas++;
}
inc_number_old = inc_number;
vars["contador_cerradas"] = contador_cerradas;
vars["contador_incidencias"] = contador;
vars["contador_no_encaminadas"] = contador_no_encaminadas;
vars["contador_encaminadas"] = contador_encaminadas;
As you may have noticed, all of this is just for displaying different sets of counts. I set some Data fields in a table calling for this variables (last four lines of the previous code block) so the report shows this counts. Well, all of this works perfectly when running via the preview tab in the workspace, or hitting the html option in the "Run" menu, but when I try to run it via web viewer, all of the counts display 0 (probably the default value of the variables). I'd be very thankful if anyone could give me some help in this. Somehow I've got some other scripts running on cells, onRender too, that are working ok regardless the preview option I choose.
p.s. I'm working with Birt v2.5.1, I know it's a bit old, but it's the only supported version to integrate with BMC Remedy ARS, and that's what I need it for. Thanks!!
回答1:
BIRT has different script flows for "direct" output and different for Web Viewer. There are two report creation phases: "generation" and "presentation", see BIRT events flow diagrams. In "direct" generation onCreate
and onRender
events are mixed and triggered together through generation phase (onCreate row 1 ; onRender row 1 ; onCreate row 2 ; onRender row 2 etc.). initialize
script is exeuted once, before all.
In opposite, Web Viewer has split generation and presentation phases: first all onCreate
are executed, then report is virtually closed (think "all script data is lost"), then all onRender
are executed. initialize
is executed twice, first time before generation phase (onCreate), second time before presentation phase (onRender). onRender
may not have access to row['...']
variables, but have access to it's report element attributes, like this.foo
.
It is good to have all data manipulation in onCreate
rather than onRender
script, because script variables are kept in one consistent phase. Presentation, for some pages may be ommited (I'm not sure), so you may have wrong results when jumping between pages in web viewer.
If you have to pass some data between generation and presentation phase, you have to store it in persistent global variable:
setPersistentGlobalVariable("name", value); //in generation phase
...
var value = getPersistentGlobalVariable("name"); //in presentation phase
There is no need to define that variable in Report Designer, just use functions above. Only one small trap may be encountered when using persistent global variables - they must be serializable in Java (it is not obvious feature for some Java data types).
来源:https://stackoverflow.com/questions/12160153/birt-script-behaves-differently-via-web-viewer