I have 2 date fields in oracle apex, Date1 is mandatory needs to be input by user and Date2 needs to prepopulate as (Date1+2 years) then user clicks the save button to save the values in database.
Then, if user clicks Date2 and change to something else, it should take that value and save.
Eg:
1.User inputs Date1 - 02/07/2019
2.Date2 should automatically populate as - 02/07/2021 but should not be saved in database.
3.User clicks save button to save data.
4.User wants to change Date2 to - 05/10/2019
5.User clicks save to save data.
I tried to set value using dynamic action for step2, but step4 is not working whenever I click save button, it's recalculating back to Date1+2 years.
Please help.
Suppose you have P1_ID (primary key), P1_DATE1 and P1_DATE2 on your form.
Create a dynamic action to set value of P1_DATE2 on change of P1_DATE1. Use PL/SQL Expression as type and PL/SQL Expression
ADD_MONTHS(TO_DATE(:P1_DATE1,'DD/MM/YYYY'),24);
Set "Fire on initialization" to false so it won't recalculate P1_DATE2 when the screen loads for an existing record - that might be the cause of the behaviour you're seeing.
It makes sense that you only want the dynamic action to fire for a new record so you could add a server-side condition in your dynamic action of "ITEM IS NULL" for item P1_ID.
Related
I have a table ORDERS which contains column ORDER_DATE. I have created a Chart as a Bar type.
Right now, the chart returns all the orders because I did not specify a Maximum Rows. The date on the x-axis and the number of orders on the y-axis.
How can I add a form for the user to select a range of dates and return only the values for those dates?
Example:
Doesn't necessarily have to be a calendar. A dropdown is fine as well. Or even a 'text' input since that is the easiest way.. I just need to know how to go about creating this feature. Your help is appreciated. Thank you.
First create a page item as date picker or some other plugin you already have to let users select a date or date range. (make sure that when user selects a date, the page item value is set by using a dynamic action or by a setting that your plugin has (set item value after selection kind of setting) )
Then create a new view with the source of your ORDERS table but it should have a where statement as it filters records by your page item such as:
select count(1)
from ORDERS
where order_date between :P1_DATE_FROM and :P1_DATE_TO
Set the source of the chart to this new view.
After user sets a value, refresh the chart by a dynamic action if it is not refreshed automatically.
In summary, the idea is to make your chart's source filtered by page items that users can change. Then refreshing the chart so that the new page item values are effective.
I've created an interactive report to add/update/delete employee info records in custom db table.
My end user requirement is upon entering the employee number in the EMPNO field, all the details from the oracle standard table such as employee name, marital status, gender, bday must be auto generated in the form and they will only manually input the location name and mode of exit.
Now I created 3 pages: 1.home page, 2.add page, 3.update page
On page 1 (home page)
I have here the select SQL
with checkbox
On page 2 (add page),
In the page processing portion
I have
EventAddRecord
Source: db , plsql code
Here's my sample code:
BEGIN
INSERT INTO EMPINFOTBL
(PERSON_ID,
EMPLOYEE_NUM,
EMPLOYEE_NAME,
MARITAL_STATUS,
BDATE,
GENDER,
LOCATION_NAME,
MODE_OF_EXIT
)
VALUES
(SELECT PERSON_ID FROM
PER_PEOPLE_X WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT EMPLOYEE_NUMBER ID FROM
PER_PEOPLE_X WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT FULL_NAME FROM
PER_PEOPLE WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT MARITAL_STATUS FROM
PER_PEOPLE WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT DATE_OF_BIRTH FROM
PER_PEOPLE WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
(SELECT GENDER FROM
PER_PEOPLE WHERE EMPLOYEE_NUM = :P2_EMPLOYEE_NUM),
:P2_LOCATION_NAME,
:P2_MODE_OF_EXIT
);
END;
Buttons
SAVE with dynamic action
When click add button if True submit page
Now my problem is how to do the update when I click the check box,
I want my record to be displayed in the form because currently when I click the check box the form is null
To create a new record (using Page 2), you'd create a select list item which is based on per_people table; you'd display any information you want, but you'd return employee ID:
select full_name as display_value,
employee_num as return value
from per_people
order by full_name;
After selecting desired person, enter values into P2_LOCATION_NAME and P2_MODE_OF_EXIT items. When you hit the "Save" button (which submits the page), run the process (I modified what you wrote; should be way simpler):
INSERT INTO empinfotbl (person_id,
employee_num,
employee_name,
marital_status,
bdate,
gender,
location_name,
mode_of_exit)
SELECT person_id,
employee_number,
full_name,
marital_status,
date_of_birth,
gender,
:P2_LOCATION_NAME,
:P2_MODE_OF_EXIT
FROM per_people
WHERE employee_num = :P2_EMPLOYEE_NUM;
As of updating existing values: I'd again suggest you to use the Wizard as it creates everything you need - form page is based on empinfotbl table, while "Edit" button in Interactive report sends the ID value to form page whose pre-rendering process fetches data related to employee identified by passed ID.
If you created your own page, you'll have to do it all yourself.
You said:
I want my record to be displayed in the form because currently when I click the check box the form is null
Form items are empty because Apex didn't know what to fetch. As I said: pass ID value, create pre-rendering process. Or start over with the Wizard (I prefer that option).
#Littlefoot has given a perfect answer already, here are just some extra steps that might guide you to a solution (it's the "or start over with the wizzard" piece from Littlefoot's answer). I'd suggest looking how apex generates its pages when you do it out of the box. Just for testing, follow these steps
Create a new page of type "Interactive Report" and make sure to check the "Include Form Page" attribute
Give the form page a name and select "PER_PEOPLE" as table/view name
In the 2nd page of the dialog, select the primary key column of PER_PEOPLE: person_id
Click "Create Page"
You now have a working form and report that you can further customize to your specific requirements. It should give you a good idea of how a form and a report is generally configured in APEX and it saves you a ton of time
Notices how in the report page:
The edit link has the form page as target and passes the id
The CREATE button has the form page as target without the id
In the form page
No custom code is needed to initialize the form data for the current record. Instead the native process of type "Form - Initialization" is used.
No dynamic actions are used to perform the inserts - for a form that is a bad practice. Avoid it.
No custom code is needed to perform the inserts or update. Instead the native process of type "Form - Automatic Row Processing" is used.
Study these pages and apply similar logic to your own pages. It'll be a better app.
I am using APEX 21.2.
The help says that "Display Only" Items do not store session state value and text fields with "Disabled" attribute set to yes do. But I tried to create an after header computation and set the value of a display only item and it worked. Is it wrong information or am I missing something?
Disabled
Specify whether this item is disabled, which prevents end users from changing the value.
A disabled text item still displays with the same HTML formatting, unlike an item type of Display Only, which removes the HTML formatting. Disabled text items are part of page source, which enables their session state to be evaluated. Conversely, display only items are not stored in session state.
I tried to create an after header computation and set the value of a display only item and it worked
Why wouldn't it work? It is you (a developer) who set it using a computation (which works), but end user can't modify its value as it is set to be display only so - users can just look at item's value.
A computation before rendering is always possible, that has nothing to do with session state. This is about how the item behaves on page submit.
With the "Display Only" item type you can control its behaviour on submit. Behaviour is the same for "Text Field" items that have the "Disabled" property set to on.
I did a quick test with a form on the EMP sample data set. Create a after header computation of type expression :P1_SAL + 1.
Test 1: Setting "set on page submit" on. The form renders with the salary item increased by 1. When page is saved, the new salary is saved for the record
Test 2: Setting "set on page submit" off. The form renders with the salary item increased by 1. When page is saved, the new salary is NOT saved for the record
Where did you see this help text ? I don't see anything about session state.
I use plugin Select2 on Apex.
I have scenario like this:
I have three tables: ROOM, MASTER_STUDENT and MAP_STUDENT_ROOM
One ROOM can have many STUDENT
User can select more than one student(with Select2 from MASTER_STUDENT) when create ROOM
When user edit ROOM, previously selected student show in Select2 item(selected item by MAP_STUDENT_ROOM), so user can remove or add more Student
How to achieve point number 4, item Select2 list of values is MASTER_STUDENT but with default selected by MAP_STUDENT_ROOM?
I found this documentation, but i dont know how to apply it.
I'm not familiar with the Select2 plug-in.
Have you considered using the built-in Popup LOV, which since APEX 19.1 now allows multiple selection.
Whether you're using the Select2 plug-in or the built-in Popup LOV, the issue will be the same. You have a form on ROOM, that's trying to take into account an item that isn't part of the ROOM table (its values are stored in MAP_STUDENT_ROOM). The trick is to populate the item correctly during page load so that the item can correctly display the currently assigned students.
How is the item's Source configured? If it's not, set Type to SQL Query (return colon separated value). Assuming you have a primary key item on the page for the room (e.g. P1_ID), enter a query like the following:
select student_id
from MAP_STUDENT_ROOM
where room_id = :P1_ID
Then set Used to Always, replacing any existing value in session state.
This should get the item to display correctly when the page loads. However, you'll still have to figure out how to map the values back to the MAP_STUDENT_ROOM table correctly when the page is submitted. You'll need to add some logic that first deletes rows from the room (P1_ID) that are not in the selection (e.g. P1_ASSIGNED_STUDENTS). You can use APEX_STRING.SPLIT_NUMBERS to help:
delete from map_student_room
where room_id = :P1_ID
and student_id not in (
select column_value
from apex_string.split_number(:P1_ASSIGNED_STUDENTS, ':')
)
Then you can insert rows that are in the selection but not already in the room.
insert into map_student_room (
room_id,
student_id
)
select :P1_ID,
column_value
from apex_string.split_number(:P1_ASSIGNED_STUDENTS, ':')
where column_value not in (
select student_id
from map_student_room
where room_id = :P1_ID
)
I've not tested any of this code, but it should get the points across.
Another option would be to use an Interactive Grid instead of a list of values item. This is a classic master/detail scenario where students could be added and removed below the form region (typically only done after create).
I have a date field and a interactive grid. I am trying to generate the Interactive grid based on the value inputted in the date field.
I am trying to write the query as below :
select pap.effective_start_date , pap.effective_end_date
from per_all_people_f pap
where :SELECT_DATE between pap.effective_start_date and
pap.effective_end_date
Here, SELECT_DATE is the name of the Date field (datatype Date picker). I am writing a dynamic action on Change of Date field, and refreshing the interactive grid region.
But when I change the value in Date field, it doesn't return any rows.
I have done a similar change where my interactive grid was based on a dropdown. There I had to set the "page action on selection" to Submit, and it worked. But here, since it is a Date field, the "Page Action on selection" property doesn't appear on the page .
Can somebody please suggest, how can I achieve this.
You need to explicitly convert your bind variables, which are treated as strings, to dates.
to_date(:SELECT_DATE)
The format mask will come from the application properties, or you can be explicit with that, too.