Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Multiple optional parameter.
alecsia
<p>Good morning!</p>
<p> </p>
<p>I have a report with multiple parameter and I am using</p>
<pre class="_prettyXprint">
AND (HR_APPOINTMENT.C_DEPARTMENT IN (****) OR HR_APPOINTMENT.C_SUBMISSION1 IN (****)
OR HR_APPOINTMENT.C_SUBMISSION2 IN (****))</pre>
<p>in my DataSet and</p>
<pre class="_prettyXprint">
this.queryText = this.queryText.replace("****", params["STR_C_DEPART"]);</pre>
<p>in the BeforeOpen script.</p>
<p> </p>
<p>I need this parameter to be optional at the same time. How can I script it??? Usually I am using something like </p>
<pre class="_prettyXprint">
var where="";
if ( params["DATE_BEGIN"].value != null) {
if (where=="") {
where = "DOC.DOC_DATE >= '" + params["DATE_BEGIN"].value + "'";
}
else {where = where + " AND DOC.DOC_DATE >= '" + params["DATE_BEGIN"].value + "'"}
}</pre>
<p>with "1=1" in the DataSet.</p>
<p>But I am not sure how can I integrate multiple “xxx†in this condition?</p>
Find more posts tagged with
Comments
alecsia
<p>I have figured this out:</p>
<div>
<pre class="_prettyXprint">
if(params["STR_C_DEPART"].value == null){
this.queryText = this.queryText.replace("****", "0");
} else{
this.queryText = this.queryText.replace("****", params["STR_C_DEPART"]);
}</pre>
</div>
<p> </p>
Matthew L.
<p>Glad you were able to figure it out.</p>
<p>Here is the solution I was working on:</p>
<p> </p>
<p>Change your query to the following:</p>
<pre class="_prettyXprint _lang-sql">
AND (1=1)
</pre>
<p>Then in your Data Set's beforeOpen statement, use the following code:</p>
<pre class="_prettyXprint _lang-js">
var whereClause = "";
if(params["STR_C_DEPART"].value != null && params["STR_C_DEPART"].value != ""){
whereClause += "HR_APPOINTMENT.C_DEPARTMENT IN ('" + params["STR_C_DEPART"].value +"')";
}
if(params["STR_C_SUB1"].value != null && params["STR_C_SUB1"].value != ""){
if(whereClause != ""){whereClause+=" OR ";}
whereClause += "HR_APPOINTMENT.C_SUBMISSION1 IN ('" + params["STR_C_SUB1"].value +"')";
}
if(params["STR_C_SUB2"].value != null && params["STR_C_SUB2"].value != ""){
if(whereClause != ""){whereClause+=" OR ";}
whereClause += "HR_APPOINTMENT.C_SUBMISSION2 IN ('" + params["STR_C_SUB2"].value +"')";
}
if(whereClause != ""){
this.queryText = this.queryText.replaceAll('1=1',whereClause)
}
</pre>
alecsia
<p>Thank you a lot! I will save this anyway!</p>