Wednesday, July 16, 2014

Using a Date Picker in APEX


Adding a Date Picker to a page

Gee, this took me ages to figure out. 
I wanted a date picker on a home page that could have a start date and an end date selected, and then open a page with the information for just between those dates. 
I messed around with format masks, application globalisation settings, to_date, to_char etc and it drove me mad. Every time I tried to open the page, it said "no data found".

I still don’t know if this is possible – passing a date from one page to another, so the solution is to not use the home page, but direct to a new page, then enter the dates there, then have a ‘go’ button that submits the page with the dates. Phew.

Create a new page, select a Report, and enter the query something like this
 
select distinct user_name,sum(billable_hours) from client_data
where entry_date between :P17_START_DATE and :P17_END_DATE
and client_name not like '%one%'
and client_name not like '%MGA%'
and client_name is not null
group by user_name
order by 2 desc

Next, create the 2 items - P17_START_DATE and P17_END_DATE as Date Picker Items:

 

You can let everything default and just click "Next", then "Create Item" .

If you try and run the page, you'll see this:


 You need to add a button - Call it something like 'Go', and all you need to do is select 'Submit" for the action:


Save this, run the page, enter some dates using the calendar icons:

 

Then click the "Go" button:


 You can change the "No Data Found" to something like "Pick a Start and End Date Using the Calendar Icons" to make it more intuitive.

On the Home page, just put a button called "Date Range" and have it direct to this page (17 in this case).

No comments:

Post a Comment