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)
How Do I Trim?
JDD
Hi, I need to trim an ID number in a report. In CrystalReports I can use the the trim function (e.g., left(<dataelement>) + right(<dataelement>)
How would I script it in BIRT?
Thanks for any help (just started using BIRT--don't know JavaScript yet).
JDD
Find more posts tagged with
Comments
bhanley
What does the data look like before it is trimmed and what does it need to look like post-processing? Let me know and i will give you a quick example script to get you going.
JDD
Hi bhanley,
I need to substitue the JRFC with "FCR-" and remove all numerals except whole numbers (or if that can't be done, then to the last four places (e.g., 0032):
pre-trim = JRFC0000001032
post-trim = FCR-1032
Thanks for the quick response and help.
JDD
bhanley
Attached is a sample doing just what you describe (see the thumbnail). I added a new column binding to the table that uses a Regular Expression and some Java Script to handle the magic parts. <br />
<br />
You will have to update the sample's Data Source to point to whatever location you save the CSV to see this run.<br />
<br />
Here is the expression: <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>var myregexp = /JRFC[0]*(.*)/;
var match = myregexp.exec(dataSetRow["Data"]);
if (match != null) {
"FCR-" + match[1];
} else {
"RegExp Failed";
}</pre>
<br />
Good Luck!
JDD
Thanks for going the extra step to provide me with zipped example. Unfortunately, I got an error on accessing your report--it appears you're using a newer version than I am (IBM is still using RptDesigner 2.2.1).
I attempted to apply your code as an onPrepare script for my "id" dataelement, but got an error on preview:
The following items have errors:
ReportDesign (id = 1):
+ There are errors evaluating script "var myregexp = /JFCOM[0]*(.*)/;
var match = myregexp.exec(dataSetRow["id"]);
if (match != null) {
"FCR - " + match[1};
} else {
"ReqExp Failed";
}":{1}.
What am I doing wrong?
Thanks for any help. JDD
bhanley
It should still be fine on 2.2, I am not doing anything too new inside BIRT. You just need to shift where you build out the expression.
Select the table. Look tot he bottom of the IDE and select the Binding tab (see attached thumbnail). From there add a new binding, and for the expression, use the java script to do the transformation of the data.
let me know how it goes.
JDD
My appologies for dragging this out for you--i'm a beginner.
I added a binding as a javascript as you instructed, see attached thumbnail.
Got an error:
The following items have errors:
ReportDesign (id = 1):
+ A BIRT exception occurred: org.eclipse.birt.core. See next exception for more information.
org.eclipse.birt.core
I appreciate your patience.
bhanley
Did you update the Java Script to find your data? You need to make this change:
var match = myregexp.exec(dataSetRow["Data"]);
should be
var match = myregexp.exec(dataSetRow["id"]);
If you have made that change, attach your design so I can have a look.
JDD
Yes, I have been using "id" vice "data".
I have uploaded the design which relies on an integration with IBM ClearQuest (uses SQL query definition), so I can't include the data. I am, without the additional binding you provided, able to successfully pull the data into the report using the attached design.
Thanks very much.
JDD
bhanley
Two small issues:
1) In the Javascript you need to change the } to a ] in the IF clause (when there is a match). this is what was causing your error.
2) Double-click on the "id" field. In the expression entry, use the "ShortID" that you have created in the bindings table.
That should set you straight.
Let me know if you are good. We will get there, things are just about working.
JDD
Hi, I made the code change, but that didn't seem to affect it.
Sean, on the IBM list, recommended I try a computed column expression using your code and that worked. Your code worked for him, both on the computed table experssion, as well as a direct data element expression in the table. I must be applying the direct data element expression incorrectly.
Appreciate the code, and my appologies for dragging it out. This is a very helpfull list--I'm learning a lot.
This issue is closed.
JDD