Thursday, February 4, 2010

Default Value for Date Field in Query Criteria

I got a question about how to assign default value for Date type field available in Query Criteria. Developer had a requirement to initialize Date type query field with date equal to 10 days before current date. This requirement is very simple for ADF and can be implemented in 5 minutes without writing any code.

Download sample application - DateSearch.zip. This sample returns default value for HireDate attribute on page load automatically:


In order to implement this requirement, open View Criteria definition and assign Bind Variable parameter to HireDate attribute. Its very important, make sure you uncheck Ignore Null Values checkbox:


This will initialize Bind Variable with Null value, when user will try to search with empty HireDate attribute value. Otherwise you will get Missing In and Out parameters SQL error.

For getting correct default date value, you can use Groovy language for Bind Variable default value expression:

5 comments:

Kalyan said...

Hi,

In my application i tried the same.

but the date is not getting displayed.

I am not able to understand why it is not displaying though i followed the same as per your blog.

Thanks,
Kalyan

Siva Sankar said...

shi,

I tried the same its working fine.
but if i want to search date with time fallows am/pm in search its not allowing design time modifications can you give some solution this is scenario, while we want to select date it asking date in pop only i want to display date-time am/pm as we observer in B2B reports screen.please can u give some solution it urgent

Batimba said...

How could I define default currentDate value for executables variables and not view based

Unknown said...

Hi Andrejus,
Got help from this blog post.
Thanks :)

Regards!
Sameera

Mohamed Mitkees said...

Can i Show the time in the Search criteria beside the date?