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)
Newbie BIRT Developer looking for date variables
JagThripp
<p>Hi There esteemed BIRT developers.</p>
<p> </p>
<p>I am new to developing in BIRT, however I have used a few other report development tools in the past.</p>
<p> </p>
<p>I am starting off small here, so apologies for the stupid question.<br><br>
I have tried searching for a solution to my hurdle but alas nothing seems to full my needs.</p>
<p> </p>
<p>I am trying to develop a listing report for Maximo users that they can run themselves and uses a date range as the input parameters for the report i.e. DateFrom and DateTo, I am just not sure how to integrate this into the report OPEN query.</p>
<p> </p>
<p>sqlText = "select p.displayname "<br>
+ " ,LT.LABORCODE "<br>
+ " ,LT.CRAFT "<br>
+ " ,LT.REFWO "<br>
+ " ,LT.STARTDATE "<br>
+ " ,LT.REGULARHRS "<br>
+ " ,LT.PAYRATE "<br>
+ " ,WO.WORKTYPE "<br>
+ " ,wl.description "<br>
+ " from labtrans lt "<br>
+ " join workorder wo on lt.refwo = wo.wonum "<br>
+ " left join worklog wl on (wl.recordkey = wo.wonum and wl.class = 'WORKORDER') "<br>
+ " join person p on LT.LABORCODE = P.PERSONID "<br>
+ " where LT.STARTDATE between to_date('01/01/2014, 'dd/mm/yyyy') and to_date('15/12/2015', 'dd/mm/yyyy') "<br>
+ " order by LT.STARTDATE desc ";</p>
<p> </p>
<p>Once again apologies for the elementary question.</p>
<p> </p>
<p>Jag</p>
<p> </p>
<p> </p>
Find more posts tagged with
Comments
jfranken
<p>On the Data Explorer tab, you'll see "Report Parameters". Add a parameter for each data value you want the user to enter (they will be prompted to enter the values when the report is run). In your Data Set query, put a question mark (?) as a placeholder in the where clause for each parameter value. Select the "Parameters" option in the Edit Data Set window. A Data Set parameter should automatically be created for each question mark in the query. Link the Data Set parameters to the Report Parameters in the Data Set parameter edit window.</p>
<p> </p>
<p>Alternatively, you can modify the query in code by setting this.querytext = "yourquery" in the beforeOpen event of the Data Set. The parameter values are referenced as: params["paramName"].value. This is only required for complex queries where the automated functionality has issues inserting the parameter values.</p>
JagThripp
<p>Hi Jeff thanks for the reply.<br>
I have modified the report to your sugesstion, bu tI have one question on the set up of the query in the Open Script.<br><br>
Can I use the "?" placeholder like this?</p>
<p> </p>
<p>sqlText = "select p.displayname "<br>
+ " ,LT.LABORCODE "<br>
+ " ,LT.CRAFT "<br>
+ " ,LT.REFWO "<br>
+ " ,LT.STARTDATE "<br>
+ " ,LT.REGULARHRS "<br>
+ " ,LT.PAYRATE "<br>
+ " ,WO.WORKTYPE "<br>
+ " ,wl.description "<br>
+ " from labtrans lt "<br>
+ " join workorder wo on lt.refwo = wo.wonum "<br>
+ " left join worklog wl on (wl.recordkey = wo.wonum and wl.class = 'WORKORDER') "<br>
+ " join person p on LT.LABORCODE = P.PERSONID "<br>
+ " WHERE LT.STARTDATE BETWEEN TO_DATE('?', 'dd/mm/yyyy') and to_date('?', 'dd/mm/yyyy') "<br>
+ " order by LT.STARTDATE desc ";</p>
<p> </p>
<p>I have added the Variables FromDate and ToDate to the DataSet Parameters.</p>
<p> </p>
<p>I must say I am no longer getting the error I was, but now nothing is returned.</p>
<p> </p>
<p>Also I am not being prompted for the dates in the range I am querying for using this mothod.</p>
<p> </p>
<p>I am using Eclipse 3.7.1</p>
<p> </p>
<p>Thanks again.</p>
jfranken
<p>Hi Jag,</p>
<p> </p>
<p>I don't know what you are referring to when you say the "Open" script.</p>
<p> </p>
<p>Assuming you're working in any recent version of the BIRT Designer, try the following:</p>
<p> </p>
<p>1. Create a new report and add a new Data Source and Data Set.</p>
<p> </p>
<p>2. Go to the Query tab in the Data Set editor and enter the following query:</p>
<p> </p>
<p>select p.displayname, LT.LABORCODE, LT.CRAFT, LT.REFWO, LT.STARTDATE, LT.REGULARHRS,</p>
<p>LT.PAYRATE, WO.WORKTYPE, wl.description<br>
from labtrans lt<br>
join workorder wo on lt.refwo = wo.wonum<br>
left join worklog wl on (wl.recordkey = wo.wonum and wl.class = 'WORKORDER')<br>
join person p on LT.LABORCODE = P.PERSONID</p>
<p> </p>
<p>3. Make sure it returns data and then save the Data Set.</p>
<p> </p>
<p>4. Click the Data Set on the Data Explorer tab to make sure it is selected, and then click the Script tab in the Layout area</p>
<p> </p>
<p>5. Go to the beforeOpen event</p>
<p> </p>
<p>6. Type in the following code:</p>
<p> </p>
<p>this.queryText = this.queryText + " WHERE LT.STARTDATE BETWEEN TO_DATE('" + params["fromDate"].value + "', 'dd/mm/yyyy') and to_date('" + params["toDate"].value + "', 'dd/mm/yyyy') order by LT.STARTDATE desc";</p>
<p> </p>
<p>7. On the Data Explorer tab, go to Report Parameters and create two new parameters named "fromDate" and "toDate"</p>
<p> </p>
<p>8. Drag the Data Set to the Layout area to create a table.</p>
<p> </p>
<p>9. Run the report.</p>
<p> </p>
<p>You should be prompted to enter the parameter values when the report runs. The values you enter should filter the data in the report.</p>
<p> </p>
<p>The code in step 6 gets the parameter values entered by the user, creates the "where" clause filling in those values, and appends the clause to the query.</p>
<p> </p>
<p>Important note: I cannot test the query or the code. Hopefully it will run, but you might have to debug it. Also, in the final version, it would be good to add some code to validate the parameter values prior to creating the "where" clause.</p>
<p> </p>
<p>The question mark notation that I mentioned previously only works if you have a simple "where" clause and is only used in the Data Set editor on the screen where you enter the query. It does not require scripting, only linking the Data Set parameters to the report parameters. Give the code above a try first and see if that works as a way to create the desired "where" clause.</p>