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)
How to make Datasource path dynamic
sanjaym
I have a monthly datasource and it points to a different folder location every month i.e Jan10, Feb10.
Main folder: c:Monthly Data
Sub folders:
Dec09
Jan10
Feb10
Mar10
Here you see that the main folder is static but the report points to a new sub folder every month.
Instead of changing the data source path every month how can I make it dynamic.
I can create a parameter to select the month and year from a drop down (having values as Jan10, Feb10 etc). But how to use this parameter value in the datasource.
I am using text data sets.
In short I want to use Dynamic Datasources and Dynamic Datasets because the path changes every month and even the dataset i.e. name of the text file as it is also suffixed with month and Year.
Please suggest if there is a better way to do it.
Regards
Sanjay
Find more posts tagged with
Comments
pricher
Hi Sanjay,
Assuming that you are using a Flat File Data Source and that you have defined a string parameter named "pFolder", you can override the beforeOpen() method of your data source with the following script:
folder = reportContext.getParameterValue("pFolder");
this.setExtensionProperty("HOME",folder);
This will dynamically change the path of your data source based on the parameter value.
Hope this helps,
P.
sanjaym
Thanks for the reply pricher.
Looks like this will work. I am getting an issue here.
As I said that the user will select month and year from the parameter but the datasource value should be "c:Data FolderFeb10", if the user selects Feb10.
I am not able to concatenate the hardcoded value "c:Data Folder" with the parameter value "Feb10" and assign it to string folder in the BeforeOpen.
Please help.
Also,
Can you please help me on how to assign value to a parameter based on the value of some other parameter.
Thanks
sanjaym
Hey Pricher,
Also how can I set a dynamic value to the filename of the dataset. As you are aware that I am using the text file for populating the dataset.
Thanks again
Sanjay
pricher
Sanjay,
Assuming that you have a flat file in "C:Data FolderJan10" and "C:Data FolderFeb10", the attached report design will dynamically connect to one of the flat files based on the paameter value you pass when running the report.
I didn't change much of the design except concatenating the parameter value to "C:Data Folder". However, please note that you have to escape the backslashes in your script. The beforeOpen method now looks like this:
folder = "c:Data Folder" + reportContext.getParameterValue("pFolder");
this.setExtensionProperty("HOME",folder);
As for assigning a parameter value based on the value of another parameter, you could probably use cascading parameters.
P.
sanjaym
Thanks a lot Pricher. I will try that.
pricher
And for changing dynamically the filename of the data set, you can manipulate the query directly by overriding the beforeOpen method of the data set.
For example, the following code will make your data set read from NewFile instead of OldFile:
qry = this.queryText;
qry = qry.replace("OldFile","NewFile");
this.queryText = qry;
sanjaym
Hey Pricher,
Thanks a lot. All that you answered worked perfectly.
Cheers
Sanjay