hcohen
hcohen

Reputation: 325

Using Javascript reportContext.setPersistentGlobalVariable method on Birt handlers

I trying to use reportContext.setPersistentGlobalVariable to define global variable on the OnFetch Javascript method of the data set like that:

flag = 1;
if(row.Percent>10)
reportContext.setPersistentGlobalVariable("flag", flag);

and to retrieve the variable on the beforeRender method like that:

var flg = reportContext.getPersistentGlobalVariable("flag");
if(flg==1)
reportContext.getDesignHandle().findElement("chartToHide").drop();

but by running the report receiving this error:

org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "reportContext.setPersistentGlobalVariable("flag", true);":
Fail to execute script in function __bm_onFetch().

Upvotes: 2

Views: 3693

Answers (1)

Dominique
Dominique

Reputation: 4332

In theory this code should work because the method setPersistentGlobalVariable expects a serializable object:

void setPersistentGlobalVariable( String name, Serializable obj );

but in practice in Rhino scripts it seems it can only handle a String, try this:

var flag = "1";
if(row.Percent>10)
reportContext.setPersistentGlobalVariable("flag", flag);


var flg = reportContext.getPersistentGlobalVariable("flag");
if(flg=="1")
reportContext.getDesignHandle().findElement("chartToHide").drop();

Upvotes: 1

Related Questions