Scripted Data Source "DESCRIBE EVENT"

sesker
edited February 11, 2022 in Analytics #1
I am having a hard time finding and documentation on the Scripted Data Source Describe event. I need to dynamically add columns to a data source and to a table depending on some user defined criteria in our application. The user can add as many columns to a data set for display in the UI as they want.

From what I have read, the Describe event is for that specifically. Can anyone point me to any references on it's usage? I have searched for several hours and not found anything. I did find old examples of using DEAPI for doing that, or for using java for event handling -- but I want to keep everything in javascript if possible...

Thanks in advance...

Scott

Comments

  • sesker
    edited December 31, 1969 #2
    Also, how do I dynamically add a column to a table in a scripted datasource (i.e. javascript and which event?)
  • averma
    edited December 31, 1969 #3
    Hi Scott,
    You can use dataSetMetaData.addColumn() to add columns in describe event of the data set. To add table columns you would write java script to the onPrepare event handler of your table. Here is a link that has an example:
    http://www.eclipse.org/forums/index.php?t=msg&goto=492448&


    Ashwini
    Warning No formatter is installed for the format ipb
  • sesker
    edited September 1, 2010 #4
    Are you referring to add a java class as an event handler? I would rather to it entirely in javascript in the report event handling scripts.

    Is there any docs on the that call, or what is available in the describe event? Is the addcolumn the same as the Java API? The problem is there is no documentation for the javascript calls and what is available in the various events (other than the autocomplete when you do something like: this.<eclipse gives you autocomplete>
  • averma
    edited December 31, 1969 #5
    Hi Scott,
    I have attached an example that uses javascript in describe event handler to add columns. It uses addDataSetColumn() to add columns.
    To find out what is available in the event handler, I usually switch to Palette view and then use the objects from there. The auto suggest feature usually lets me know my options.
    In this particular case it did not suggest me all the functions and that is a bug. Feel free to report such bugs here:
    http://www.birt-exchange.org/org/resources/bug-reporting/
    I have already reported this issue so you don't have to.

    Ashwini
    Warning No formatter is installed for the format ipb
  • Lea
    Lea
    edited December 31, 1969 #6
    Hi Ashwini,

    thanks for your example - it works perfectly. I tried to expand it for my own needs but ran into a problem. Maybe you could help again. I just added a line that creates a new object from a class that is my own (e.g.: var test = new Packages.examplePackages.ExampleClass() ). I don't even us it - just creating it. The preview via the properties (Properties->Preview Results) is still fine, but I also need the columns within the tree in the Data Explorer. This is always empty. If I remove the mentioned line, everything is fine again.

    Any hints?

    Thanks!
  • averma
    edited December 31, 1969 #7
    Hi Lea,
    If you edit the data set and go to "output columns", here you can add new columns that will show up in the data set.

    Ashwini
    Warning No formatter is installed for the format ipb
  • Lea
    Lea
    edited December 31, 1969 #8
    Hi Ashwini,

    thanks for your reply. Unfortunately this is not what I need. I still need to add the columns dynamically within the describe-event. But I need to read them from my own library.

    Thanks,

    Lea
  • averma
    edited December 31, 1969 #9
    I am not sure if I have a correct understanding of your issue. Are you saying that you can use javascript to add columns dynamically but would like to use Java instead?
    Warning No formatter is installed for the format ipb
  • Lea
    Lea
    edited December 31, 1969 #10
    <blockquote class='ipsBlockquote' data-author="'averma'" data-cid="77423" data-time="1306172773" data-date="23 May 2011 - 10:46 AM"><p>
    I am not sure if I have a correct understanding of your issue. Are you saying that you can use javascript to add columns dynamically but would like to use Java instead?<br /></p></blockquote>
    <br />
    I'd like to use both. Within the fetch-event I'd like to use the addDataSetColumn but the string that is used comes from my own java-lib.<br />
    <br />
    This works:<br />
    <span style='font-family: Courier New'>var list = ["Test", "Test2", "Test3", "Test4"]; <br />
    <br />
    while (count < list.length){ <br />
    this.addDataSetColumn(list[count],"STRING"); <br />
    count++; <br />
    } </span><br />
    <br />
    This does not work:<br />
    <br />
    <span style='font-family: Courier New'>var myVariable = new Packages.birt.Test(); <br />
    var list = ["Test", "Test2", "Test3", "Test4"]; <br />
    <br />
    while (count < list.length){ <br />
    this.addDataSetColumn(list[count],"STRING"); <br />
    count++; <br />
    } </span><br />
    <br />
    <br />
    Within the preview both versions are ok, but the tree in the explorer does not show the columns in the second case. Although I did not even use "myVariable".
  • averma
    edited June 3, 2011 #11
    Hi Lea,
    Try adding the following prefix to your script:
    importPackage( Packages.birt );
    Also make sure your java classes are available to BIRT engine:
    http://wiki.eclipse.org/BIRT/FAQ/Scripting#Q:_Where_do_I_have_to_put_my_classes_in_order_to_access_them_by_JavaScript.3F

    Let me know how that goes.

    Ashwini
    Warning No formatter is installed for the format ipb
  • Lea
    Lea
    edited December 31, 1969 #12
    Hi,<br />
    <br />
    <blockquote class='ipsBlockquote' data-author="'averma'" data-cid="77976" data-time="1307139206" data-date="03 June 2011 - 03:13 PM"><p>
    Let me know how that goes.<br /></p></blockquote>
    <br />
    I also tried your idea with the same result. The java classes I need here are "imported" as a project, and they must be available since it works within the preview, but not in the tree. Meanwhile I had to change my settings anyway and I started using the API to write the report/datasources anew. So need not to have a solution for this issue. <br />
    <br />
    But thanks a lot for your help!