Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Where to put a function that is referenced in a dataset script
Where to put a function that is referenced in a dataset script [message #652294] Thu, 03 February 2011 13:55 Go to next message
Mike Wulkan is currently offline Mike WulkanFriend
Messages: 141
Registered: July 2009
Senior Member
Hi,

I have the following Javascript function:


function fixBadDate(badDate) {
importPackage(Packages.java.text);
importPackage(Packages.java.util.date);
if (badDate == null) {
return null;
}
else {
t = badDate.substr(1,badDate.length-2);
sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
return sdf.parse(t)
}
}

which is used to cleanse some awkward data fields in the database. If I put this script directly in the computed columns expression everything works fine. However since I would like to use this function for several fields I would like to put it in a globally accessible place.

I tried putting it in the "beforeopen" script for the dataset. When I do that the dataset preview results works just fine; indicating that the function can be found, however when I run the report the initial values of my report parameters based on this dataset are no longer filled in! My guess is that this is a timing issue and I just have to find a better place to put the function.

Thanks
Re: Where to put a function that is referenced in a dataset script [message #652382 is a reply to message #652294] Thu, 03 February 2011 17:23 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Mike,

Try putting it in the initialize script for the report.

Jason

On 2/3/2011 8:55 AM, Mike Wulkan wrote:
> Hi,
>
> I have the following Javascript function:
>
>
> function fixBadDate(badDate) {
> importPackage(Packages.java.text);
> importPackage(Packages.java.util.date);
> if (badDate == null) {
> return null;
> }
> else {
> t = badDate.substr(1,badDate.length-2);
> sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
> return sdf.parse(t)
> }
> }
>
> which is used to cleanse some awkward data fields in the database. If I
> put this script directly in the computed columns expression everything
> works fine. However since I would like to use this function for several
> fields I would like to put it in a globally accessible place.
>
> I tried putting it in the "beforeopen" script for the dataset. When I do
> that the dataset preview results works just fine; indicating that the
> function can be found, however when I run the report the initial values
> of my report parameters based on this dataset are no longer filled in!
> My guess is that this is a timing issue and I just have to find a better
> place to put the function.
>
> Thanks
Re: Where to put a function that is referenced in a dataset script [message #652391 is a reply to message #652382] Thu, 03 February 2011 17:48 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike WulkanFriend
Messages: 141
Registered: July 2009
Senior Member
When I do that the initial parameter values are not filled in from the dataset
Re: Where to put a function that is referenced in a dataset script [message #652398 is a reply to message #652391] Thu, 03 February 2011 17:55 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

If you put the script in the initialize method you are making it a
global script. You can also reference from an external .js file.

Jason

On 2/3/2011 12:48 PM, Mike Wulkan wrote:
> When I do that the initial parameter values are not filled in from the
> dataset
Re: Where to put a function that is referenced in a dataset script [message #652400 is a reply to message #652398] Thu, 03 February 2011 18:27 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike WulkanFriend
Messages: 141
Registered: July 2009
Senior Member
I understand the intent and this is what I tried originally; however it doesn't work. For some reason when I do this although the dataset preview works (which implies that the script is accessible), the parameter default values are not filled in.
Re: Where to put a function that is referenced in a dataset script [message #652411 is a reply to message #652400] Thu, 03 February 2011 19:04 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Mike,

Can you work up an example with the sample db so I can test it?

Jason

On 2/3/2011 1:27 PM, Mike Wulkan wrote:
> I understand the intent and this is what I tried originally; however it
> doesn't work. For some reason when I do this although the dataset
> preview works (which implies that the script is accessible), the
> parameter default values are not filled in.
Previous Topic:How to transform data for use in a pie chart
Next Topic:screen.width function doesn't work in Birt
Goto Forum:
  


Current Time: Thu Nov 27 23:35:54 GMT 2014

Powered by FUDForum. Page generated in 0.01817 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software