In many cases applications need to send values to queries a user executes to provide context and/or security. In many of these cases the user never knows the value of these parameters (for example a customer ID or a store ID). In the case of one of my customers they were using the locale of the user to limit the data they were seeing.<br />
<br />
In the attached example I am using the embedded Classic Models database. I created an Information Object to retrieve a list of customers. On this IO I created a hidden parameter called locale. I will then filter the country based on this parameter. I am aware that locale and country are not the same but for the purposes of the demonstration it serves the purpose. I have attached the IO project.<br />
<br />
I then created a simple BIRT Report Studio template with some added code to the beforeFactory event. The simple template is also attached. In this code I retrieve the user's locale. I then loop through the data sets of the report and for each data set I loop through its parameters. I then set the parameter based on the user's locale. Code below:
var design = reportContext.getDesignHandle();
var locale = reportContext.getLocale()
var dataSets = design.getDataSets();
for (i = 0; i < dataSets.getCount(); i++) {
var dataSet = dataSets.get(i);
var parameters = dataSet.getListProperty("parameters");
for (j = 0; j < parameters.size(); j++) {
var parameter = parameters.get(j);
// BIRT Report Studio add a dataSetName: to all parameters
if (parameter.getName().endsWith(":locale")) {
// this line remvoes any linking of dataset and report parameters
parameter.setParamName(null);
// this line will set the default value (note this is an exp<b></b>ression, so it must be quoted properly)
if (locale == "en_GB") {
parameter.setDefaultValue(""UK"");
}
else if (locale == "fr_FR") {
parameter.setDefaultValue(""France"");
}
else if (locale == "de_DE") {
parameter.setDefaultValue(""Germany"");
}
else if (locale == "ja_JP") {
parameter.setDefaultValue(""Japan"");
}
else {
parameter.setDefaultValue(""USA"");
}
}
}
}