How to validate a date parameter control in report ui
Hi, I have a report ,which has a From Date and To Date field.I need to validate in the ui itself wheather the From Date entered is less than To Date when user clicks view report and show it in a message box.I tried with custom code (in Report properties Code tab) ,the message is diplayed in development enviornment but when deplyed no message is diplayed in the browser.I tried with diaplying it in label that works but it happens after the report run.What i need is,should happen before reoprt run and should not execute report till valid date is entered as we do validation in normal aspx pages.Please help with any clue.Thanks & RegardsNitin
February 24th, 2009 7:44pm

Hi, From the scenario you described, you are looking for cascading parameters. Generally speaking, we can achieve this by creating a new dataset which contain the available values base on precondition parameter "From". Create the parameter "To" base on this new dataset. If you want to see more details steps, herearetwo similar threads for cascading parameters: http://social.technet.microsoft.com/forums/en-US/sqlreportingservices/thread/643c4f7f-8b1d-4096-b478-d5fd9136bd2e http://social.technet.microsoft.com/forums/en-US/sqlreportingservices/thread/50a5b672-6b77-40ed-9401-bdc9ea4c0d69 Also, here is document about cascading parameters (2005): http://msdn.microsoft.com/en-us/library/aa337426(SQL.90).aspx Please let me know the results. Regards, Raymond
Free Windows Admin Tool Kit Click here and download it now
February 26th, 2009 7:54am

Hi, Its not related to cascading parameters,all that we needis to just validate FromDate , ToDate values before the report is run if the dates satisfy bussiness rules specifed then the reoprt is run, butif the validations fail then the user is prompted with a alert/message telling him to enter proper values.Actuallythedate parameter is rendered as Calender control andtakes care of any invalid date entered say likeleap year, out of range values that iffine , but in my case i need to apply some extra bussiness rules e.g. From Date cant be greated than ToDate etc.I achived this by some custom code (in Report properties Code tab) but the message is displayedonly in myVisual Studio evironment butwhen deployed to report server the message isnt displayed instead an error is displayedlike"(rs:..)" butthan message is not displayedas in development environment.Here istheCustom code used Function CheckSignificantDate(StartDate as Date, EndDate as Date) as IntegerDim msg as String msg = "" If (StartDate > EndDate) Thenmsg="Start Date should not be later than End Date" End If If msg <> "" Then MsgBox(msg, 16, "Report Validation")Err.Raise(6,Report) 'Raise an overflow End IfEnd Functionadd a parameterand addthe expression=CODE.CheckSignificantDate(<parameterStartdate>.Value,<parameterEnddate>.Value)It then prompts the user(but only in development enviornmentThanks &RegardsNitin
February 26th, 2009 8:18am

Hi Nitin, Thanks for your code. It is a good idea. In addition to your solution, my opinion is creating a textbox in the report. Set the expression to be "=CODE.CheckSignificantDate(Parameters!from.Value,Parameters!to.Value)". Suppose we are using table in the report. Select the table and then set the visibility base on expression: "=iif(CODE.CheckSignificantDate(Parameters!from.Value,Parameters!to.Value)="Report Validation", false, true)" After you deploy the report, you will validate the date base on your code. The following is my test code: Function CheckSignificantDate(StartDate as Date,EndDate as Date) As String Dim msg as String If (StartDate > EndDate) Then msg= Start Date should not be later than End Date else msg="Report Validation" End If CheckSignificantDate= msg End Function Thanks! Regards, Raymond
Free Windows Admin Tool Kit Click here and download it now
February 26th, 2009 10:08am

Hi Raymond, Thank you for the reply. Thesolutionyou provided is a good idea not make the tablerepresenting data,making it visiblefalse if the validationfails. But the scenario for my problem isslight different, the report shouldnot go to"run" unless the validations are successfull (e.g similar to as we have in resigtration pages ofasp.net pages where user is diplayed a popup or a label ,and the page is not redirected till all are validated ).Hereaftermakingchanges as you mentioned ,the table is made visible false,but what i want is to display messagewhen user clicks"View report" and not to move to run report tillthe datesare validated.Thanks & RegardsNitin
February 26th, 2009 10:47am

Hi Nitin, In report server, it is unlikely to show a message box as you said. Also, set visibility to be false couldnt prevent report from running data. So a possible workaround is using filter too. Edit the dataset, set the expression of the filter to be =CODE.CheckSignificantDate(Parameters!from.Value,Parameters!to.Value)=Report Validation" After that, the report couldnt run unless the parameters are available. Hope this helps. Regards, Raymond
Free Windows Admin Tool Kit Click here and download it now
February 26th, 2009 11:25am

Hi Raymond,I tried too with filter expressions as mentioned,but it wont work, sinceit just filters therecordsfromthe result set (dataset) only but doesnt stop processing of the report if thevalidations fail.The Filter expression just filtersthe recordsfrom thedateset if any. Still in search of the solution!!Thanks & RegardsNitin
February 26th, 2009 12:12pm

How about this..? Create a placeholder report that accepts report parameters, include Sub-report element which will load your actual report if validation succeeds. If validation fails, hide the sub-report and show error message for the invalid parameters. To do so, in the sub-report, create a hidden paramter, that doesnt accept null value. Pass some value (say boolean True) to this parameter (expression for this sub-report parameter will be conditional expression) when date parameters are valid. When the date parameters are not valid, dont provide any value to this hidden parameter and so automatically the report cant be processed. Also add the visibility condition for the sub-report element so that, in cases where parameters are not valid, sub-report is hidden (just to avoid showing sub-report error). ..hegde
Free Windows Admin Tool Kit Click here and download it now
February 26th, 2009 1:47pm

Hi Mahesh,Thank you for the reply :) The main problem is want to restrict the user by showing messages at first place itself for invalid inputs through alert messaage box and and not to procceed to any action till valid dates are entered.I am developing the report in SSRS 2005,using BI stuido.I have not found anyway to display message for custom date validations nor any settings,propertiesfor that Date Parameters to showmessages. The system does display's alerts if the Date fileds are left empty, even forother type of parameters too.I want tomake the system to display similaralerts for the custom date validation that i wantt implement. AS mentioned earlierbelow code doeshelp display thealert but only inpreview ofreport designer but not when thereport is run in report server after deployment. Code: Function CheckSignificantDate(StartDate as Date, EndDate as Date) as Integer Dim msg as Stringmsg = "" If (StartDate > EndDate) Thenmsg="Start Date should not be later than End Date" End If If msg <> "" ThenMsgBox(msg, 16, "Report Validation")Err.Raise(6,Report) 'Raise an overflow End IfEnd Functionadd a parameterand addthe expression=CODE.CheckSignificantDate(<parameterStartdate>.Value,<parameterEnddate>.Value)Thanks & RegardsNitin
February 26th, 2009 2:47pm

What server should do if a subscription uses invalid datetime? A message box is useless. Without build-in support of custom validation, creating a asp.net web page and using report viewer contron might be a choice. Just my thought.
Free Windows Admin Tool Kit Click here and download it now
February 26th, 2009 3:09pm

Hello Nitin, Do you have a solution to stop the Report from Running after the Validation message box is initiated? Please let me know ,DeepakReportingServices
May 18th, 2009 8:45pm

Hi, We can also use direct expression in visibility properties iif(Parameter!startdate>Parameter!Enddate,"Invalid Parameters",false) Thanks, Shobhit
Free Windows Admin Tool Kit Click here and download it now
January 22nd, 2011 9:38pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics