Home
Analytics
Parameter Validation Script Error
Pujan
Hello,<br />
<br />
I want to compare the 2 dates (start and end date). I added the following code in the "Validate" script of the End Date. <br />
<br />
<br />
df = new Packages.java.text.SimpleDateFormat("yyyy-MM-dd");<br />
df2 = new Packages.java.text.SimpleDateFormat("yyyy-MM-dd");<br />
myStartDate = df.parse(params["FromDate"].value);<br />
myEndDate = df2.parse(params["ToDate"].value);<br />
if (BirtComp.lessOrEqual(myStartDate, myEndDate)){<br />
true;<br />
}<br />
else{<br />
false;<br />
}<br />
<br />
During Preview I am getting the following error. <br />
<br />
<strong class='bbc'>org.eclipse.birt.report.service.api.ReportServiceException: Parameter "ToDate" script source validation error.</strong><br />
<br />
Can anyone please help me resolve this issue ASAP.
Find more posts tagged with
Comments
bhanley
What are the values you are supplying for start and end date?<br />
<br />
I would look at using the Date object in your JavaScript rather than SimpleDateFormat. BIRT provides a lot of means to deal with parsing dates out of the box, but those options are generally geared toward using a Date object. (You can check out the DateTimeSpan object for starters)<br />
<br />
The constructor for the Date object can accept a String. Try this script:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>Date dStart = new Date(params["FromDate"].value);
Date dEnd = new Date(params["ToDate"].value);
var date1Comp = dStart.getTime(); // milliseconds
var date2Comp = dEnd.getTime();
if (date1Comp < date2Comp) {
true;
}
else{
false;
}</pre>
<br />
Sending the dates to milliseconds is a fool-proof way to make sure you are doing a fast, accurate evaluation.
Pujan
I added the code, but still the same issue.
dStart = new Date(params["FromDate"].value);
dEnd = new Date(params["ToDate"].value);
var date1Comp = dStart.getTime(); // milliseconds
var date2Comp = dEnd.getTime();
if (date1Comp < date2Comp) {
true;
}
else{
false;
}
Pujan
Also, in case of an invalid input parameter - how to either popup a dialog box telling user that the parameter value is wrong OR show on the parameter screen that the input value is wrong. eg: if the from date is > than the to date, how to show a user that they need to change the from date.
I am new to BIRT so not sure how BIRT displays this kind of error. Or it just doesn't run the report.
Pujan
I am getting this error
org.eclipse.birt.report.service.api.ReportServiceException: Parameter "ToDate" script source validation error.
only when the input value is wrong. ( ie - start date is > than the end date).
Please help.
bhanley
Where are you executing this script? I think the error is actually being generated by you, by the simple fact you are returning false. What I think we need to look at is where you are executing the script to make sure it is firing at the right time. Secondly, what is the ultimate goal here? To determine that the two dates are valid (i.e. start is smaller than end)? If the parameters are invalid, what do you want to happen in your report?
Pujan
I am executing the code in the <strong class='bbc'>Validate</strong> script of "To Date" . The idea is to check if start date is smaller than the end date and if its not then I would like to show a msg that start date is wrong. <br />
<br />
I have created a hidden parameter to show the msg but not sure how to implement it. (ie how to make it visible in the script and whether I need to do in "Validate" or some other script").
bhanley
Returning False from the Validate scripting event will simply cause the report not to run. It is the job of the containing application to handle this error state.
If you want to validate the parameter and still run the report, move the validation JavaScript we went through earlier to the report's initialize event. Then if the validation fails, hide the things you do not want to display and show your error tag.
Another idea is to leave the validation where it is. But the new execution will always return TRUE (allowing the report to run). In the JavaScript for the validation hide the main report elements and show your error message rather than return false. After hiding and un-hiding the proper elements, you will return True having already handled the error condition.
The basic design of the report has you adding a hidden label or something similar that only gets shown when the error condition is met. Do not forget to hide the elements that should not be seen if there is an error as well.
Pujan
Thanks for explaining. It really helps.
Can you please provide me with some sample code to show the hidden field. I tried couple of different ways but its not working.
Thanks
Pujan
bhanley
Have a look at this post. It is a great guide for showing and hiding various report elements at run time.<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/devshare/designing-birt-reports/567-birt-show-hide-component/#description'>BIRT
: Show/Hide Component - Tips & Tricks - BIRT Exchange</a>
Pujan
Thanks.
I was able to resolve the issue -
I added the "DateError" Parameter on the master page and checked the "Hide Element". The in the expression I added the below code. This way if the dates are same or from date is later than to date the Date Error is shown.
if (BirtComp.equalTo(params["FromDate"].value, params["ToDate"].value))
{
false
}
else
{
if (BirtComp.lessOrEqual(params["FromDate"].value, params["ToDate"].value))
{
true
}
else
{
false
}
}
NIT
I too have the issue of validating two dates.Please provide the steps how you compared the two dates.I was not able to validate the dates.I am getting the following error
org.eclipse.birt.report.service.api.ReportServiceException: The validation for parameter "FromDate" fails.
Ganesh Hegde
<p>Even i am facing d same issue..</p><p>[color=rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;]org.eclipse.birt.report.service.api.ReportServiceException: The validation for parameter "Outlet" fails.[/color]</p><p>[color=rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;]please help me[/color]</p>