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)
mmultiple values ​​for each parameter
laye50
<div>bonjour,</div><div> </div><div>Je veux faire des parametres comme ceci :</div><div>select </div><div>a,b,c from table where a = ? and c = ? and c = ?.</div><div> </div><div>"a" peux prendre tous les valeurs ('t1, t2,t3,t4) ou (t1,t2) ou (t1) ou (t2,t4) ou .....</div><div>meme chose pour b et c</div><div>Comment puis-je faire ça? </div><div>Merci à l'avance</div>
Find more posts tagged with
Comments
kclark
<blockquote class="ipsBlockquote" data-author="laye50" data-cid="128916" data-time="1403777293"><div><p> </p><div><div>hello, </div><div> </div><div>I want to make the parameters as follows: </div><div>select </div><div>a, b, c from table where a =? and c =? and c =?. </div><div> </div><div>"a" can take all values ​​(t1, t2, t3, t4) or (t1, t2) or (t1) or (t2, t4) and ..... </div><div>same for b and c </div><div>How do I do that? </div><div>Thank you in advance</div></div><p> </p></div></blockquote><p> </p><p>It sounds like your wanting to take a multiselect parameter and include it in your query, is this correct?</p>
laye50
<div>Thank you for responding. yes that's what I want to do </div><div>more precisely, I want to have a lot of parameters to multiple choice in my application. </div><div>I'm a beginner on this technology. </div><div> </div><div>thank you</div>
kclark
<p>I'll write an example for you and post it here. Basically you'll need to parse out the comma separated string that's created by a multiselect parameter then change your query in the beforeOpen().</p>
kclark
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Take a look at the example I create. It uses three multiselect parameters for Country, State, and City. I used the following code to break down the parameter selected as an array and I looped through them to reconstruct my query.</p><pre class="_prettyXprint _lang-">var p = params["City"].value;var pCityArray = p[0];var qText = "";if(p.length > 0) { pCityArray = "'" + p[0] + "'"; for(i=1; i<p.length; i++) { pCityArray += ",'" + p[i] + "'"; } qtext = "select * from CLASSICMODELS.CUSTOMERS where classicmodels.customers.city in (" + pCityArray + ")"}else{ qtext = "select * from CLASSICMODELS.CUSTOMERS where classicmodels.customers.city in ('" + p[0] + "')"}var p = params["State"].value;var pStateArray = p[0];if(p.length > 0) { pStateArray = "'" + p[0] + "'"; for(i=1; i<p.length; i++) { pStateArray += ",'" + p[i] + "'"; } qtext += " or classicmodels.customers.state in (" + pStateArray + ")";}else{ qtext += " or classicmodels.customers.state in ('" + p[0] + "')";}var p = params["Country"].value;var pCountryArray = p[0];if(p.length > 0) { pCountryArray = "'" + p[0] + "'"; for(i=1; i<p.length; i++) { pCountryArray += ",'" + p[i] + "'"; } qtext += " or classicmodels.customers.country in (" + pCountryArray + ")";}else{ qtext += " or classicmodels.customers.country in (" + p[0] + ")";}this.queryText = qtext;</pre><p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Let me know if this helps or if I need to modify this any to your needs
. Also, notice I added a label above the table so you can see what the query looks like that's be executed.</p>
laye50
<div><div>Hello there, </div><div> </div><div>This is exactly what I was looking for.
</div><div>Thank you for your help. </div><div> </div><div>best regards</div></div><p> </p>
kclark
<p>You're welcome, let us know whenever you've got a question!
</p>
minthril
<p>Very nice example
</p><p> </p><p>I have similar question - I would like to create on the parameter page list but not like here: List Box.</p><p> </p><p>I would like to have<strong> list of checkboxes</strong> (based on rows from querry) - it is more user friendly/intuitive when user wants to pick more than one value. Better than have "ctrl" key pressed and make multiselect [in yours example it works of course].</p><p> </p><p>Is it possible to make such a thing?</p><p> </p><p>Best regards,</p><p>minthril</p>
kclark
<p>
@minthril
-- This can be done but I'm pretty sure that you'd have to create a custom parameter page for this. I can write up an example in a bit, have you created a custom parameter page before?</p>
minthril
<p>Yes, I have created some poor custom parameter page to have quite nice datepickers (if I understood properly - we speak about 'dynamic web project' with use of <em>birt.tld</em> and deploing to glassfish/tomcat application server).</p><p> </p><p>It would be very nice to have some fundamentals for this case:)</p>
kclark
<p>Sorry for the late reply
I'll work on an example for you today and post it when I'm done.</p>
kclark
<p>Take a look at this sample code, it's not 100% complete but it should be enough to give you a good idea of how to get this done</p><pre class="_prettyXprint _lang-"><%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%><%@ taglib uri="/birt.tld" prefix="birt" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><script> var chkbox = new Array(); function populate() { document.getElementById('oldparams').style.display = 'none'; var paramValues = new Array(); var checkboxes = new Array(); var param = document.getElementById('5'); for(i=0; i<param.options.length; i++) { paramValues[i] = param.options[i].value; checkboxes[i] = "<input type="checkbox" name="newparam" + i + "" value="" + param.options[i].value + "">" + param.options[i].value + "<br>"; chkbox.push("newparam" + i); } for(i=0; i<checkboxes.length; i++) { document.getElementById('newbox').innerHTML = document.getElementById('newbox').innerHTML + checkboxes[i]; } } function viewReport() { // Parse out the selected checkboxes here and construct a new URL alert('working....'); }</script></head><body onLoad="populate()"><div id='oldparams'><birt:parameterPageid="report1"name="page1"reportDesign="customparameters.rptdesign"isCustom="true"pattern="frameset"><birt:paramDef id="5" name="Customers" /></birt:parameterPage></div><br><div id="newbox" style="width: 200px; height: 100px; overflow-y: scroll;"></div><br><input type="submit" value="Submit" onClick="viewReport()"></body></html></pre><p>This creates a listbox parameter based on a report, and hides it. Then I grabbed all of the values from the list box and constructed a div with checkboxes instead. The only thing that needs to be completed here is to find all the checkboxes that have been selected, create a comma seperated string, and pass them back into the report via a hidden required parameter. Once you've got the values in that parameter you can parse them in the data set's beforeOpen() and add them to the query. I hope this helps
</p>
minthril
<p>Thanks a lot kclark
It worked almost fine. One of my colleagues helped me to correct javascript side of this example. I will paste this (<script>) part here for other people who maybe will use this example.</p>
<pre class="_prettyXprint">
<script>
var chkbox = new Array();
function populate() {
document.getElementById('oldparams').style.display = 'none';
var paramValues = new Array();
var checkboxes = new Array();
var param = document.getElementById('9');
for(var i=0; i<param.options.length-1; i++){
paramValues[i] = param.options[i].value;
checkboxes[i] = '<input type="checkbox" name="newparam' + i + '" value="' + param.options[i].value + '">' + param.options[i].value + '<br />';
chkbox.push("newparam" + i);
console.log(checkboxes);
}
for(var i=0; i<checkboxes.length; i++) {
document.getElementById('newbox').innerHTML = document.getElementById('newbox').innerHTML + checkboxes[i];
}
}
function viewReport() { // Parse out the selected checkboxes here and construct a new URL alert('working....'); }
}
</script>
</pre>
kclark
<p>Thanks for posting your script! I'm glad you could get it working.
</p>