Date validation for Dash board prompt Calendar control
One the question you see regularly on the forums is how to validate date in dashboard prompt if more important with the use of the calendar control.

In OBIEE the Date validation for Calendar control is not happening when user tries to enter any invalid dates (i.e. Dates in invalid formats and strings).otherwise if you select from the calendar pop up window it works good.

Because of this date column mismatching at date data type we are getting error in our Reports. So to make it fair we need to handle the calendar control input values if the user enters directly. For this we have to change the calendar control functionality when the user hits the µGo´ button in dashboards as Go button is sending our prompt input values to reports. In OBIEE the GO button functionality was defined in globalfilterprompt.js. It is located in two locations 1. <install_dir>\OracleBi\web\app\res\b_mozilla\prompts 2. <install_dir>\OracleBI\oc4j_bi\j2ee\home\applications\analytics\analytics\res\b_mozilla\prompts For example let¶s validate the date to dd/mm/yyyy or dd-mm-yyyy format Open globalfilterprompt.js and search for the GFPFixDateTime() function it is the function which handles the calendar control date. function GFPFixDateTime(sDate, sPrefix) {

else return (sDate). sPrefix) { ////////////////////////SHIVA DATE VALIDATION CODE///////////////////////////////////////////// var sDisplayDate = ³31/12/1960 . } . Step2: Comment/Delete the code (here I made it in Bold) in this functionGFPFixDateTime(sDate. sPrefix) Step3: Add the following code to function GFPFixDateTime(sDate. //To make this date as default date if you entered wrong format date // var datePat = /^(\d{1. sPrefix) and now your code should look like this: function GFPFixDateTime(sDate. Step1: Make sure that you should taken a back up of this file as if you not done this changes properly it will effects the prompts behavior and breaks the pages to work.´).match(datePat).search(/^\s*$/) != -1) return ³´.if (/*(sDate == ksDropDownUnspecified) || */(sDate == ksDropDownAllChoices) || (sDate == ksEditBoxAllChoices)) return sDate. //Validating the date with Regular expression// var matchArray = sDate. // check for null or just whitespace else if (sDate == null || sDate. return sDisplayDate. if (matchArray == null) { alert(³Please enter date as either dd/mm/yyyy or dd-mm-yyyy. } Now here we need to change the existing behavior of this function.2})(\/|-)(\d{4})$/.2})(\/|-)(\d{1.

´). } if (month == 2) //To validate no of days in Feb month based on year// { var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)). year = matchArray[5]. } if (day < 1 || day > 31) //To validate Day no in Date// { alert(³Day must be between 1 and 31. } if ((month==4 || month==6 || month==9 || month==11) && day==31) //To validate correct no of days in month// { alert(³Month ³+month+´ doesn¶t have 31 days!´) return sDisplayDate. return sDisplayDate.day = matchArray[1]. return sDisplayDate. if (day > 29 || (day==29 && !isleap)) { alert(³February ´ + year + ´ doesn¶t have ´ + day + ´ days!´). . month = matchArray[3].´). if (month < 1 || month > 12) //To validate month number in date// { alert(³Month must be between 1 and 12.

Now open the OBI Dashboard and give the input values to calendar control. 2 and 3 in two locations. .return sDisplayDate. Step5: Restart Oracle BI Java host and Oracle BI Presentation server and also OC4J (For better results clear your browser cache and history). ////////////////////////SHIVA DATE VALIDATION CODE///////////////////////////////////////////// } Step4: Make the steps 1. } } return (sDate).

(For me I don¶t have data before 31/12/1960 even you should make sure the date for which you don¶t have any data) To avoid this message add no-results view in your answers report.This is because we have fixed this in Our code to make as default date for calendar if any wrong input entered by User.If you click the ok button of this alert box then you will see the report like this If you observed the Date value in message it is taking date ³31/12/1960´. Add message to No Results View .

OBIEE IS BETWEEN Date Validation for dashboard prompt Normally when we are working with Calendar date with Between operator we are not seeing any alert message if the user enters the inappropriate dates.\OracleBI\web\app\res\b_mozilla\prompts 2. And add the following code in this loop after values declaration.js.If you want to validate in your own format you can validate in the same way how i have done. For this we need to some workaround to alert the user for proper dates to input.js otherwise you will loss the actual behavior of the prompt if you not done properly. To validate date for correct format I have already posted in this blog:http://shivabizint.Now check the Report in Dashboard with proper validaton and Message: In this Post I have validated the date only for dd/mm/yyyy or dd-mm-yyyy format.wordpress.com/2009/04/13/datevalidation-for-dash-board-prompt-calendar-control/ Now to alert the user if he is entering inconsistent dates for Between operator we need to add simple code in globalfilterprompt. .you need to alter this file in two locations 1.\OracleBI\oc4j_bi\j2ee\home\applications\analytics\analytics\res\b_mozilla\prompts Steps to do: Step1: As usual take a backup of your globalfilterprompt. Step2: Open Globalfilterprompt.js and search for the if (sNewOp == ³between´) loop.

sOp = ³lessOrEqual´. } Step3: Now your if (sNewOp == ³between´) should be like this if (sNewOp == ³between´) { var sVal = tValues[0].Code snippet: if(sVal2 < sVal) { alert(³Value-2 should be greater than Value-1 ). // var bVal = (sVal && (sVal != ksDropDownAllChoices) && (sVal != ksEditBoxAllChoices)). else if (sVal && !sVal2) tF. Now check the Date with between parameter to alert user: . if (sVal == ksDropDownAllChoices || sVal == ksEditBoxAllChoices || sVal == ksDropDownNone) sVal = ³´. } } Step4: Now restart Oracle BI Java Host and Oracle BI Presentation server and also OC4J for better results (I am always doing this). // var bVal = (sVal2 && (sVal2 != ksDropDownAllChoices) && (sVal2 != ksEditBoxAllChoices)).sOp = ³greaterOrEqual´. } //Shiva code for BETWEEN Operator// if (!(sVal && sVal2)) { if (!sVal && sVal2) tF. else tF.sOp = ³prompted´. var sVal2 = tValues[1]. //Shiva code for BETWEEN Operator// if(sVal2 < sVal) { alert(³Value-2 should be greater than Value-1 ). if (sVal2 == ksDropDownAllChoices || sVal2 == ksEditBoxAllChoices || sVal2 == ksDropDownNone) sVal2 = ³´.

Till next time« .

Sign up to vote on this title
UsefulNot useful