Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Global Variables and Property Binding
ncervaen
hi guys,
I want to have a parameter that will give a list box of devicenames started by "Location_" for the user to choose.
So I have linked the parameter to a data set where I have to put in the query somewhere "devicename like 'Location_%'".
"Location" is coming from reportContext like this:
TCR_IUSER = "com.ibm.tivoli.reporting.api.reportEngine.IUserInfo";
userInfo = reportContext.getAppContext().get(TCR_IUSER);
userName = "unknown";
if (userInfo != null) {
userName = userInfo.getUserPrincipal();
}
userName is the Location.
My problem is that I cannot associate anywhere (should be in Property Binding) the variable userName with the query.....
I tried global variable, global persistent variables, etc, but "property Binding" just does not work this....
I tried using the beforeOpen script in the dataset, but the parameter doesn't go there when it calls the data set...
Ayn help please?
Nuno
Find more posts tagged with
Comments
mwilliams
So, you're wanting to grab the location from the external application and pass that to a query? Where are you writing this script at? Can you attach your design?
ncervaen
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="82855" data-time="1316119737" data-date="15 September 2011 - 01:48 PM"><p>
So, you're wanting to grab the location from the external application and pass that to a query? Where are you writing this script at? Can you attach your design?<br /></p></blockquote>
<br />
Hi Michael,<br />
<br />
Thanks for replying.<br />
I'm with my ipad, I dont ahve access to my birt instance to copy you now the design.<br />
Let me reformulate my question in what I really want.<br />
I want to be able to use the variable userName, defined above in beforeFactory, in a data set that will be called by a dynamic parameter.<br />
The dynamic parameter should provide a list box containing device names. This list depends on the logged user (user example:parisoffice)<br />
Hope its clearer.<br />
Thanks again,<br />
Nuno
cypherdj
Hi Nuno,<br />
<br />
if I understand correctly, you have a dynamic report parameter, which is bound to a dataset which itself should be parameterised using a value (username) which you can access from the reportContext, right?<br />
<br />
If so, why not simply create a dataset parameter username, and define its expression to be the script you have provided above?<br />
<br />
And in your dataset's query, you use the ? notation to identify the parameter.<br />
<br />
Have a look at the attached example, I simulated passing the username into the reportContext by adding the following to the initialise method of the report:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext.getAppContext().put("username", "Jennings")</pre>
<br />
note that this example was generated with BIRT 2.5.1,<br />
<br />
Let me know if this answers your query,<br />
Cedric
ncervaen
Hi Cedric,
Yes, that's what I want. (I actually wanted to use "like '?%'", but ok, I have a workaround for that)
Anyway, your solution doesn't work for me. Im using birt 2.2.1 as it's the latest version supported by Tivoli Common Reporting from IBM
and this might be the problem.
I tried to attach a new report with what you proposed, but it failed, so I'm copy pasting the code at the bottom.
As a test, if I change the parameter defaultValue to "someuser", it works, but not with reportContext.getAppContext().get("username").
Maybe there's another way to do this for birt 2.2.1?
Thanks and cheers,
Nuno
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="
http://www.eclipse.org/birt/2005/design"
; version="3.2.15" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.2.1.r221_v20070924 Build <2.2.0.v20070924-1550></property>
<property name="units">in</property>
<property name="comments">Copyright (c) 2007 <<Your Company Name here>></property>
<html-property name="description">Creates a blank report with no predefined content.</html-property>
<method name="initialize"><![CDATA[reportContext.getAppContext().put("username", "HFR12345")]]></method>
<text-property name="displayName">Blank Report</text-property>
<property name="iconFile">/templates/blank_report.gif</property>
<parameters>
<scalar-parameter name="test" id="10005130">
<property name="valueType">dynamic</property>
<property name="dataType">string</property>
<property name="paramType">simple</property>
<property name="isRequired">false</property>
<property name="controlType">list-box</property>
<property name="dataSetName">test</property>
<expression name="valueExpr">dataSetRow["HotspotCode"]</expression>
<expression name="labelExpr">dataSetRow["HotspotCode"]</expression>
<property name="mustMatch">true</property>
<property name="fixedOrder">true</property>
<property name="distinct">true</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
</parameters>
<data-sources>
<oda-data-source extensionID="org.eclipse.birt.report.data.oda.jdbc" name="opspanel" id="382">
<property name="odaDriverClass">com.mysql.jdbc.Driver</property>
<property name="odaURL">jdbc:mysql://opspanel.be.sceur.ch/ops</property>
<property name="odaUser">ops</property>
<encrypted-property name="odaPassword" encryptionID="base64">b3Bz</encrypted-property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" name="test" id="10004867">
<list-property name="columnHints">
<structure>
<property name="columnName">LocationCode</property>
<property name="displayName">LocationCode</property>
</structure>
<structure>
<property name="columnName">HotspotCode</property>
<property name="displayName">HotspotCode</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">LocationCode</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">HotspotCode</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">opspanel</property>
<list-property name="parameters">
<structure>
<property name="name">param1</property>
<property name="dataType">string</property>
<property name="position">1</property>
<expression name="defaultValue">reportContext.getAppContext().get("username")</expression>
<property name="isInput">true</property>
<property name="isOutput">false</property>
</structure>
</list-property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">LocationCode</property>
<property name="nativeName">LocationCode</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">HotspotCode</property>
<property name="nativeName">HotspotCode</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
</list-property>
<property name="queryText">select dim_hotspot.LocationCode,dim_hotspot.HotspotCode from dim_hotspot
where HotspotCode = ?</property>
</oda-data-set>
</data-sets>
<styles>
<style name="crosstab-cell" id="4">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
</report>
cypherdj
ok, maybe I didn't explain properly. I don't use tivoli, so I had to find a way to simulate this, which i did by putting a default username in the report context manually, and then simply retrieving this value using the script expression.
so to get the behaviour you want, you would remove the initialise script and replace the script expression for your parameters with your tivoli call.
does that make sense?
ncervaen
Hi Cedric,
Thanks for that, but unfortunately it didn't work.
I now understand why your first proposal didn't work. It's because, when running the report, the initialize script is called after the user have selected the "Report Parameters" and pressed OK, so any variable defined in the initialize script is never available at this moment.
Regarding your last proposal, I put all the tivoli call in the parameter section of the dataset and I got the error:
"Error evaluating Javascript expression. Script engine error: TypeError: Cannot call method "getUserPrincipal" of null (source#2)
"
And this tivoli call works fine when it's called from the beforeFactory script.
So, I'm thinking that if I cannot use reportContext variables before the initialize script then it seems that what I want to do is not possible. Can you please confirm that this is correct, so I can move on?
Thanks again,
Nuno
cypherdj
Hmmm, I don't see how this would be a problem since you're not using a report parameter but a data set parameter, which are quite different.
Did you look at this thread?
http://www.ibm.com/developerworks/forums/thread.jspa?threadID=325069&tstart=0#14457093
This is what I was going to suggest next, using setPersistentGlobalVariable. the approach to getting the username is slightly different from what you're doing, accessing the http request on the report context.
Then in your report parameter script, you would simply call:
reportcontext.getPersistentGlobalVariable("user")
I would find it extremely surprising that noone using tivoli has faced this problem (retrieving the logged-in user from within BIRT), so I would be pretty confident that it is indeed possible, but as I said before I'm not using Tivoli myself, so I cannot confirm this.
Hope this helps in solving your problem,
Cedric
ncervaen
Hi Cedric,
Regarding your first comment, I'm using the expression in a dataset parameter, but this is called from a "Report Parameter".
I've looked at the thread and I tried to use "req = reportContext.getHttpServletRequest(); user = req.getParameter("userName");", but again, the reportContext at this instant is apparently null as I get again the same error:
"Error evaluating Javascript expression. Script engine error: TypeError: Cannot call method "getParameter" of null (source#2)"
Regarding your last comment, I can get the username from Tivoli but only when I have my Tivoli call code in beforeFactory or initialize. But this 2 procedures are only called after the user pressing ok when choosing the "Report Parameters" and I need to have the username before the user pressing ok, so that I can show a listbox of devicenames specific for that user.
Thanks again,
Nuno
cypherdj
Ok, you are probably right in the order of the execution of the various scripts, it will evaluate the parameters first in the webviewer, then initialize and finally beforeFactory (I've actually put a log message in each to check the order
).<br />
<br />
My last idea would have been the beforeOpen function of the data set, but you've posted earlier that you already had tried this before.<br />
<br />
Maybe you could repost your question with a new thread title that would draw more attention to the Tivoli aspect, maybe "accessing Tivoli user from parameter dataset", it might attract tivoli specialists attention and maybe they will have a more definitive answer than I have
<br />
<br />
out of curiosity, are you using IBM Tivoli Common Reporting? If so, which version?<br />
I found this <a class='bbc_url' href='
http://blog.gulfsoft.com/2011/03/passing-tcr-userid-in-birt-reports.html'>intriguing
post</a> which seems to indicate an issue with TCR 2.1.<br />
<br />
Sorry I could not be of more assistance in solving your problem,<br />
Cedric
ncervaen
Hi Cedric,
Yes, I've tried the beforeOpen, but beforeOpen is not called when its the "Report Parameters" that call a dataset.
I've seen that IBM post before. I'm using TCR 2.1 with ITNM 3.8 not 3.9, so I still didn't face that problem
I've opened a ticket with IBM and they've replied that this is considered a "customization" of reports and that their policy is that I would have to request to our account manager the development of this customization
.
Anyway I'll update this post if they'll find a solution.
Thanks again for your time. your assistance was great.
cheers,
Nuno
ncervaen
Hi guys,
IBM confirmed that this is not possible to do as the TCR variable is not available when running the report parameters.
The solution provided by them is to use a drill-through. Which is basically having 2 reports. The first one will link to the second.
For example, the first report will provide a list of devices for the logged user and every device will be an hyperlink to the second report that will display more info about it.
Thanks again for your time,
Nuno Cervaens