global variables, data rows and legends

RAURAU Junior Member
edited December 31, 1969 in Designing Analytics Reports
Hi all BIRT gurus.

Before question, I'm beginning with Java and BIRT, but well experienced with low level programming (assembler and C, C++).

I'm trying to set a different text for legends. I've been searching in forums for 2 days but yet not found the right answer. The problem is that I couldn't read my global variables right, it always return NULL.

I'm doing the reading in OnFetch in dataset events like this:
reportContext.setPersistentGlobalVariable("code_desc",row["bdesc"]);
reportContext.setPersistentGlobalVariable("code_num",row["bssr"]);

then in event beforeDrawLegendItem come this:

var code_desc = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("code_desc");
var code_num = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("code_num");
lerh.getLabel().getCaption().setValue( code_num.toString()+code_desc.toString() );


The problem is that Im always getting this exception: Cannot call method "toString" of null at line 95 of chart script:''..... it seems that my variables are both null. I've tried with this.rowdata.getcolum("bdesc").... and nothing, really dont' get what is happening, or maybe I'm reading rows inside the wrong event.

BTW, community definitelly needs a book on BIRT scripting, I bought both BIRT books on amazon (BIRT field guide and Integrating BIRT ) and not a single world on scripting. Whos gonna write that book??? I'll buy it RIGHT NOW

Comments

  • VirgilVirgil Administrator EM admin
    edited December 31, 1969
    Hi RAU,

    Can you try doing the toString() when setting your global variable. I had a heck of a time when testing this myself and found this approach seemed to work best like below. I think this was an issue for me since one of the database fields was a number.

    Data Set onFetch()

    var xyz=row["CUSTOMERNUMBER"];
    reportContext.setPersistentGlobalVariable("code_desc",xyz.toString());


    function beforeDrawLegendItem(lerh, bounds, icsc)
    {

    teststring = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("code_desc");
    lerh.getLabel().getCaption().setValue( teststring );
    }

    Virgil Dodson
    OpenText Analytics Developer Community
    https://forums.opentext.com/forums/categories/analytics

  • RAURAU Junior Member
    edited December 31, 1969
    Hi Virgil,

    thanks for your answer, I solved this one but not by the scripting path, I just cooked a result inside a stored procedure and put it as a text category in Y axis, I was doing a pareto graph.

    The guys at BIRT need to move all fields like legends, titles, etc. to variables, it would be so easy to just set a computed column and then bind to that.

    I'm really loving BIRT but I think that lacks of a good script debugger / logger to debug our scripts. I'm moving all my scripting issues (calculations, aggregates,etc.) to MYSQL stored procedures, is faster than BIRT and easier to debug, at least for me that I'm not that proficient in Java.

    Anyway BIRT is by far easier and better than Jasperreports, I've tried both before deciding which one to use in my project, and I'm not disappointed at all with results so far, pure eye candy!!

    thanks again,

    Ricardo.
Sign In or Register to comment.