Tuesday, June 29, 2010
Great Article on SQL grouping by time periods
http://weblogs.sqlteam.com/jeffs/archive/2007/09/10/group-by-month-sql.aspx
Tuesday, June 15, 2010
Birt Reports on Aim Desktop - Trailing 13 months
I like to show the trailing 13 complete months in chart reports that auto-load on the work desk so that the user can see the annual trend and the same month from the year prior. I riffed of the last second of the month sql discussed in my "nice looking date parameters" article to come up with the where clause for the chart dataset.
First, read up on the dateadd function here. http://www.w3schools.com/sql/func_dateadd.asp
Maybe there's a cleaner way to do this, but it works.
Here's a simple application:
select ph_workorder, ph_date_created
from phase
where ph_date_created > dateadd (m, -13, dateadd
(ss,-1, convert(datetime, convert(varchar,(dateadd (mm,1,getdate() - day (getdate())+2)-1), 101))) )
order by ph_date_created
Wednesday, June 9, 2010
Nice Looking Date Parameters in Birt
select distinct convert(datetime, convert(varchar,dateadd(day,-datepart(day,ae_p_pst_e.status_date)+1,ae_p_pst_e.status_date), 101)) as starting_date,
right(convert(varchar, status_date, 106), 8) as display_name
from ae_p_pst_e
order by date desc
right(convert(varchar, status_date, 106), 8) as display_name
from ae_p_pst_e
Tuesday, June 8, 2010
Shortening long string fields and removing carriage returns
Inevitably, your users will want a work order list report. In AiM, the work order and phase description fields are up to 255 chars long, which can eat up a lot of space in the limited space available on your report. To avoid killing tons of trees every time a report is printed, there are a couple options to shorten the text passed to the report.
Use the sql command SUBSTRING to limit the number of characters retrieved from the database.
select
substring (ph_desc, 1, 60) as ph_desc
from phase
which means that 60 chars, starting with the first character, of the ph_desc field will be retrieved.
Then, AiM allows users to enter carriage returns and line feeds, so I do a couple more modifications to remove those since they can also eat up space.
--to remove carriage returns
select
replace (ph_desc, CHAR (13), ' ') as ph_desc
from phase
and/or
--to remove line feeds
select
replace (ph_desc, CHAR (10), ' ') as ph_desc
from phase
All of these can be combined in the following way.
select
replace (replace (substring(ph_desc,1,60), CHAR (13), ' '), CHAR(10), ' ') as ph_desc
from phase
Friday, June 4, 2010
Report Item Visibility based on parameter
Multiple, Multi-Select Parameters
var endOfQuery = " WHERE workorder.proposal IN ('" + params["proposal"].replace(/,/g,"','") + "')";
this.queryText += endOfQuery;
Another way to view this would be:
var endOfQuery = " WHERE tablename.columnname IN ('" + params["parametername"].replace(/,/g,"','") + "')";this.queryText += endOfQuery;
This will append the where clause onto the end of the query. It may be possible to modify this script to accomodate additional where clauses. It's been a while since I used this method and I may have tried and failed or maybe I never tried it.
My current preferred method is to write the query, but to include the where clause. A script is still required, but write string variables in the where clause. The script replaces these strings with selected parameter values.
The where clause may be something like this:
where tablename1.columname1 in ('xxx') and tablename2.columname2 in ('yyy')
Here's the script.
this.queryText = this.queryText.replace("xxx",params["parameter1"].value.join("','" ))
this.queryText = this.queryText.replace("yyy",params["parameter2"].value.join("','" ))
Hyperlinks from a Birt Report to Aim
In Birt, build your report. Then select the particular field for which the hyperlink is to be applied. Click on the properties editor and choose hyperlink. Select Link to and the hyperlink editor is displayed. In the hyperlink editor, select URI. Click the Fx button on the right to open the Expression builder. Type the URL of the AIM application surrounded by double quotes and end by referring the unique value that will direct the hyperlink to the corresponding Aim record.
A couple examples:
"https://gwuapp.assetworks.com/fmax/screen/WO_VIEW?proposal=" + row ["PH_WORKORDER"]
"https://gwuapp.assetworks.com/fmax/screen/SC_INVOICE_VIEW?tranxNo=" + row ["tranx_no_con"]
To find the exact URL, you can see it Aim, by doing a search and then selecting a record. The URL that is displayed is the unique url associated with that record. From that you'll understand the basic format, and how you need to modify it as a dynamically constructed hyperlink in BIRT.
Browse Print Reports from Aim
The report needs to be set up to accept multiple values for a single parameter. To do this, I tried the two different methods for passing multiple values to a parameter and found that only this one worked.
In the script tab of your dataset, enter the following script
var endOfQuery = " WHERE workorder.proposal IN ('" + params["proposal"].replace(/,/g,"','") + "')";
this.queryText += endOfQuery;
At runtime, the above script appends to the query by adding a where clause. As always, you need to be very specific (including case) with the name of the parameter.
Put the report into AiM. Don’t specify that it is visible in any modules. In view/select, pick screens and pick the screen where this report should be visible. In the case of a work order browse, pick wo_browse.
UPDATE: I found a limitation in Aim that affects the output of this report. Because Internet Exploder has a limitation on the number of characters for the URL, Aim limits the number of proposal #'s it sends as parameter values to the report. The report will only output the work orders displayed on the screen. So if your search returns 3000 work orders, you'll only get the 25 or so work orders visible on the screen.
Wednesday, June 2, 2010
Drill Through from a primary BIRT report to a secondary BIRT report
Because both reports will eventually in the AiM document repository, a certain sequence must be followed when creating the links between the two reports.
First, draft the primary report. Then draft the secondary report. Place the secondary report into the document repository. The document repository is comprised of a bunch of folders with names like 1341 and 1342. Inside the 1341 folder will be a document titled 1341_0. In order to have link between the two reports that will work on your desktop during development and in production on the AiM server, you need to create a relative path between the two reports similar to what would be found on the server.
Put the secondary (or target) report in the document repository. Note the tranx_num. On your desktop, create a folder in the same directory as the primary report. Name the folder with the tranx_num. Place the secondary report in the folder and rename it to the tranx_num, plus _0. It should be something like this (1341_0.rptdesign)
Now go to the primary report and create the linkage using the interactivity/hyperlink features in BIRT.
Update: Since 5.0, there are some changes to the doc repo that affect how drill throughs function. First, I did the drill through hyperlink as url as opposed to a path described above. Maybe it works with path as well, but I was more comfortable with url.
First create both the reports with no hyperlinks/drill throughs. Name them something like primary and secondary to keep it straight. For the secondary report, create report parameter(s) that you intend to pass data to from the primary report. Make the parameters required. Place that report into Aim via report manager and run it to make sure it works. When you run the report, copy the url and paste it into notepad.
It should be something like:
https://gwuapp.assetworks.com:8443/reportviewertest/frameset?__fmaxDocId=0EE1E3FC-D340-45A4-ACA8-87C999166CAF&__fmaxReportId=1094&ph_shop=WC14
where ph_shop is the parameter value and everything up that refers to the report manager and doc repo.
Go to the primary report. Select the field that will be your hyperlink/drill through. Select hyperlink in properties. Select URI in the next radio button. Then bring up the expression builder. You are going to build a javascript expression to describe the target report.
Paste the copied url from notepad into the window. Put a double quotes at the begining and delete the parameter value string (like WC14 in the example) and put double quotes at the end.
Then add a + and select the row value corresponding the hyperlink.
Should look like this:
"https://gwuapp.assetworks.com:8443/reportviewertest/frameset?__fmaxDocId=0EE1E3FC-D340-45A4-ACA8-87C999166CAF&__fmaxReportId=1094&ph_shop="+row["ph_shop"]
Load the primary report into Aim report manager. Run it and test.