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)
change parameter value?
dahweeds
Can I change a parameter value? Where will I best run the script?
example:
Need to run query based on different field if user checks some box.
if (params["checkedBox"] == true){
params["dataField"].value = "trueChoice";
} else {
params["dataField"].value = "falseChoice";
}
In my mind, that should set the parameter for this kind of query
"SELECT " + params["dataField"].value + " FROM database"
Also, I'd like to display the changed parameter value on the
report in a dynamic text box.
but I tried this kind of changing parameter value script in many places with no changes.
I also tried setParameterValue("dataField", "falseChoice") in a initialize script but it did not seem to work.
I could do something like this in PHP, but have not enough java/Birt experience.
Thanks in advance for any help.
From David
Find more posts tagged with
Comments
mwilliams
Hi David,
Can you explain this a little more? Are you wanting to change which data field is brought in by the query based off of a true/false parameter? Or are you wanting to let the user specify a field to bring in by the query? Or am I not understanding correctly at all? Some sample data might help to visualize what you're wanting. Thanks.
dahweeds
Thanks for trying to help.<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>Hi David,<br />
<br />
This is correct.<br />
Are you wanting to change which data field is brought in by the query based off of a true/false parameter? <br />
<br />
When the user logs in to the report server, they use a true false check box to specify which date field they want for the basis of selecting records. <br />
<br />
That is all I have for know which field they want to use. <br />
<br />
Or are you wanting to let the user specify a field to bring in by the query? <br />
No. The use does not pick or enter any text to decide the date field.<br />
<br />
Some sample data might help to visualize what you're wanting. Thanks.</p></blockquote>
<br />
table looks something like this:<br />
reportDate | incidentDate | blobOfDescription |<br />
02/01/08 | 01/30/08 | whatever, whatever...|<br />
<br />
I can make a params["whichDate"] too put in the dynamic query <br />
<br />
"SELECT " + params["whichDate"] + " FROM database"<br />
<br />
but cannot change the value of params["whichDate"] between reportDate and incidentDate. <br />
<br />
maybe this is clearer?
mwilliams
David,
It's a little clearer. So, if they select, for example, "true", then you want to grab just the "reportDate" and "description" fields from the database with the query? And if "false" is selected, then you want to grab just the "incidentDate" and "description" fields? Let me know if I've got it right.
dahweeds
Yes, that is the situation.
another query could look like this:
SELECT " + params["dataField"] + " AS theDate WHERE " + params["dataField"] + " >= 'Jan 1, 2008'"
So I'd like to
setParameterValue("dataField", "reportDate")
or
setParameterValue("dataField", "incidentDate")
Before I run the query.
mwilliams
David,<br />
<br />
Since you don't need the input from the user to know what field you're grabbing from the database except for the "true/false" from the checkbox. You should be able to just do something like this in your beforeOpen of your dataSet:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if (params["CheckBox"].value == true){
this.queryText = "select reportDate as theDate, description from database";
}
else{
this.queryText = "select incidentDate as theDate, description from database";
}
</pre>
<br />
Since you're wanting to display this value in the report somewhere in a dynamic text box, you could just set a variable here that you would call from that dynamic text box in the report. Something like:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if (params["CheckBox"].value == true){
this.queryText = "select reportDate as theDate, description from database";
reportContext.setPersistentGlobalVariable("dataField", "reportDate");
}
else{
this.queryText = "select incidentDate as theDate, description from database";
reportContext.setPersistentGlobalVariable("dataField", "incidentDate");
}
</pre>
<br />
Then you could recall this value in a dynamic text box with:<br />
<br />
reportContext.getPersistentGlobalVariable("dataField");<br />
<br />
This would bypass having to set a parameter to use in the query.
dahweeds
thanks for the help.
It is close to what I have. I have used the different static queries in the dependent box of the query builder.
the global parameter seems useful.
I just want to finish .
appform
<p>Please give a dummy report example for the above case.</p><p> </p><p> </p>
mwilliams
<p>What is your BIRT version? Maybe you can explain more about your exact scenario and I can make a sample closer to what you're needing.</p>
appform
<p>sorry for late update.</p><p> </p><p>please refer this post.My requirement is same.</p><p><a data-ipb='nomediaparse' href='
http://www.eclipse.org/forums/index.php/mv/msg/377894/915709/#msg_915709'>http://www.eclipse.org/forums/index.php/mv/msg/377894/915709/#msg_915709</a></p><p> </p><p>I
am unable to download provided example.so provide a example.</p><p> </p><p>Regards,</p><p>Appform.</p>
mwilliams
<p>Not sure why you're unable to download it. I had no issues. I've attached the zip file Jason posted. Let me know.</p>
appform
<p>Thanks.</p><p> </p><p>My problem also solved
.I got the way for dynamic queries in birt query builder.</p><p> </p><p>My another question :-mysql supports PREPARE and EXECUTE commands.Does BIRT support these commands?</p><p> </p><p>eg:-</p><p> </p><p>[font="arial, sans-serif;"]<span style="font-size:10pt;">We are having 3 tables such as<br />
<br />
<span class='bbc_underline'><strong>User</strong></span><br />
<br />
<strong>Id Name</strong><br />
<br />
1 ABC<br />
<br />
2 XYZ<br />
<br />
3 MNP<br />
<br />
4 PQS<br />
<br />
5 UVW<br />
<br />
<span class='bbc_underline'><strong>Team</strong></span><br />
<br />
<strong>Id Name</strong><br />
<br />
1 t1<br />
<br />
2 t2<br />
<br />
3 t3[/font]</span></p><p><br />
[font="arial, sans-serif;"]<span style="font-size:10pt;"><strong><span class='bbc_underline'>Performance</span></strong><br />
<br />
<strong>Id User_id Team_id Count Created_date</strong><br />
<br />
1 1 t1 6 2014-01-11<br />
<br />
2 1 t1 4 2014-02-12<br />
<br />
3 2 t2 2 2014-03-11[/font]</span></p><p> </p><p>I am able to execute below query in mysql,</p><p> </p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> SET
@QUERY
= 'SELECT[/color][/font]</span></p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> SUM(P.count) AS revenue,[/color][/font]</span></p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> DATE(P.created_date) AS created_month [/color][/font]</span></p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> FROM users AS u[/color][/font]</span></p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> LEFT JOIN performance AS P ON P.user_id = u.id[/color][/font]</span></p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> LEFT JOIN teams AS t ON t.id = P.`team_id`[/color][/font]</span></p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> WHERE t.`id` = P.team_id '; [/color][/font]</span></p><p> </p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> PREPARE stmt1 FROM
@QUERY
;[/color][/font]</span></p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;"> EXECUTE stmt1;[/color][/font]</span></p><p> </p><p>[color=#1f497d;][font="calibri, sans-serif;"]<span style="font-size:11pt;">But when i am executing in BIRT query builder, i am getting error . [/color][/font]</span></p><p> </p><p>Regards,</p><p>Swapna.</p>
mwilliams
<p>Glad you got it working!</p><p> </p><p>It's very possible that the jdbc oda doesn't support the functions you're trying to use.</p>