Tuesday, March 29, 2011

Passing TCR UserID in BIRT Reports

Many times, you might want to display/determine the TCR user name that is invoking the reports. While there is no GUI way of doing this within BIRT, a simple Javascript is all you need. Here is how to do it in BIRT

  1. Select a blank area in the report. This should display report properties in the Property Editior.

  2. Now click on the "Script" tab for the report displayed at the bottom of the main work area. (where Preview/Layout tabs are).

  3. In the script drop down, select "Before Factory" and paste the javascript code below.


    TCR_IUSER = "com.ibm.tivoli.reporting.api.reportEngine.IUserInfo";

    userInfo = reportContext.getAppContext().get(TCR_IUSER);

    userName = "unknown";

    if (userInfo != null) {

    userName = userInfo.getUserPrincipal();

    }



  4. Now you can use the userName javascript variable in your reports to identify/display the TCR User.

  5. For example, to display the UserName, insert a "Dynamic Text" item anywhere in your report and enter the following value. "User name = " + userName
Hope this helps.

3 comments:

Ashwini Verma said...

Great tip on using scripting in your BIRT report to get information from app context. Can you submit a link to your article on BIRT Exchange devshare (http://www.birt-exchange.org/org/devshare/) so more BIRT developers can benfit from it?

Venkat said...

Thanks for the suggestion! Just posted in BIRT-Exchange as well.

Gaurav said...

hi venkat ,,,
just tried the same code in TCR2.1 /ITNM3.9 ,, but its doesn't seem to work, though it did work perfectly on TCR 1.2/Wbtop2.2 ..any clue what could be wrong ... thanks in advance
Gaurav