I've created a select list item and need to reference this list on another page. how do i get the user input, place it in a variable that can be used to calculate the total value of the selected item on another page?
code for the select list which is displayed on a report to allow for amount to be stated:
select item_id,
itemname,
item_price,
apex_item.hidden(1, item_id) ||
apex_item.hidden(2, item_price) ||
apex_item.select_list(
p_idx => 3,
p_value => nvl(null,'item'),
p_list_values => '1,2,3,4,5,6,7,8,9,10',
p_show_null => 'YES',
p_null_value => 0,
p_null_text => '0',
p_item_id => 'f03_#ROWNUM#',
p_item_label => 'f03_#ROWNUM#',
p_show_extra => 'NO') "item"
from item
the select to display the sum will look something like this:
select itemname,
item_price,
'select list value',
('select list value'* item_price) as sum
from item
how do i get the chosen amount from the select list?
Thanks
Oracle APEX has package APEX_APPLICATION which contains collections with names from G_F01 to G_F50. When you use any function from apex_item to create an item inside a report, you pass a number into p_idx parameter. In your example it is 3 for the select list. This value corresponds to one of collections mentioned above - G_F03 in this case.
All values from user's input are passed to these collections after the submit. So you can to write in the after submit process following code:
for i in apex_application.g_f01.first .. apex_application.g_f01.last loop
insert into my_table (id, new_value)
values (apex_application.g_f01(i), apex_application.g_f03(i));
end loop;
This code shows how to insert values from user's input into my_table. Note, that these collections contain only rows changed by user. If a user gets a report with 10 rows and changes 3 of them, each collection will have 3 elements.
Also, APEX has APEX_COLLECTION API to store temporary data.
For more information, see in the documentation: APEX_APPLICATION, APEX_COLLECTION.
UPD.
There are two ways to work with the data further - using a table or APEX_COLLECTION. I have never worked with APEX_COLLECTION, so here is an example with a table.
If you use a table to store temporary data, you need columns for ID, user's name and data (data from the Select List in your example). On the page with the report you need to do this after the submit:
delete from my_table where user_name = :APP_USER;
for i in apex_application.g_f01.first .. apex_application.g_f01.last loop
insert into my_table (id, new_value, user_name)
values (apex_application.g_f01(i), apex_application.g_f03(i), :APP_USER);
end loop;
On the next page, where you need to use this data, you create the following report:
select t.new_value, ...
from my_table t, ... <other tables>
where t.user_name = :APP_USER
and t.id = ...
and <other conditions>
Related
I added a drop-down field P1_TABLE_NAME on the Data Load Source page of the APEX Data Load Wizard, where users can choose a value. This value should be populated into the TABLE_NAME column in the database. The TABLE_NAME is also defined as a lookup value in Oracle Apex. In the paste area the users will enter various information about the tables. So the sequence should be as follows:
User Selects value in the P1_TABLE_NAME drop-down menu.
Paste something into the paste area.
Click next.
Two columns are presented in the Data/Table Mapping page first column contains the information pasted into the paste area.
Second column contains the value selected in the P1_TABLE_NAME drop down menu.
Ideally the second column contains the lookup value for that table e.g. user enters Blah and the value in the second column of the Data/Table Mapping. Maybe if APEX can be configured to extract the extra value in the same select as the other values in the 'SPREADSHEET_CONTENT'
I used the following tutorial: http://www.jrweth.com/oracle-apex-data-loader-part-1-adding-custom-columns/
Created the extra item P1_TABLE_NAME but the form on the Data/Table Mapping only displays the values entered into the paste area.
The code that I used:
FOR UPLOAD_ROW IN (SELECT SEQ_ID
FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'SPREADSHEET_CONTENT')
LOOP
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE (
p_collection_name => 'SPREADSHEET_CONTENT',
p_seq => UPLOAD_ROW.SEQ_ID,
p_attr_number => '2',
p_attr_value => : P1_TABLE_NAME);
END LOOP;
I also tried messing about with the APEX Data Validation SQL query. Hoping that maybe I can just update the query to include additional fields, which will then be included in the list of columns presented on the subsequent Data/Table Mapping page.
select n001 as row_num,
wwv_flow_lang.system_message( 'DATA_LOAD.' || c049 ) as action,
c001, c002, c003,
c004, c005, c006,
c007, c008, c009,
c010, c011, c012,
c013, c014, c015,
c016, c017, c018,
c019, c020, c021,
c022, c023, c024,
c025, c026, c027,
c028, c029, c030,
c031, c032, c033,
c034, c035, c036,
c037, c038, c040,
c041, c042, c043,
c044, c045, : P1_TABLE_NAME
from apex_collections
where collection_name = 'LOAD_CONTENT'
and c049 in ('INSERT','UPDATE', 'FAILED')
order by seq_id
The APEX Data Loader can only load into a single target table. The list of columns presented on the Data/Table Mapping page comes from the Data Load Definition, which is defined once for a single table.
One way I've overcome this limitation is to create a staging table with all the columns from all the tables, then written custom PL/SQL after the data has been loaded to move it to the user's selected target table.
Having a report of the services table with checkbox for each row, I am trying to get the values of the selected service, so that when I click on next I can create a report with the services chosen in the new page.
I have tried in this way:
Report of the services table.
select code,
name,
cost,
apex_item.hidden(p_idx => 1,
p_value => code) ||
apex_item.hidden(p_idx => 2,
p_value => cost) ||
apex_item.checkbox2(p_idx => 3,
p_value => code) CheckBox
from services
I created a process.
Source:
begin
apex_collection.CREATE_OR_TRUNCATE_COLLECTION ('SDBA_ORDER_ITEMS1');
for i in 1..apex_application.g_f01.count loop
apex_collection.add_member(
p_collection_name => 'SDBA_ORDER_ITEMS1',
p_c001 => to_number(apex_application.g_f01(i)), -- service_code
p_c002 => to_number(apex_application.g_f02(i)), -- cost
p_c003 => to_number(apex_application.g_f03(i)) -- service_code
);
end loop;
end;
Server-side Condition:
begin
for i in 1..apex_application.g_f01.count loop
for j in 1..apex_application.g_f03.count loop
if apex_application.g_f01(i) = apex_application.g_f03(j) then
return true;
else
return false;
end if;
end loop;
end loop;
end;
Report on the next page.
select (select name from services where code = c001) as service_name,
c002 as cost
from apex_collections
where collection_name = 'SDBA_ORDER_ITEMS1'
order by 1
Report on the next page.
select (select name from services where code = c001) as service_name,
c002 as cost
from apex_collections
where collection_name = 'SDBA_ORDER_ITEMS1'
order by 1
In this report it shows all the services of the table instead of the selected ones.
How can I get only the selected rows? Can anybody help me please?
Thanks in advance.
Checkboxes are formed into dense collections, not potentially sparse like the other item types. I think this is a product of web tech, not APEX.
So if you had ID, Name, Checkbox
1 - ada - checked
2 - charles - not checked
3 - alan - checked
There would be 3 index elements in ID and Names array, and only 2 in the checkbox array - and index element 3 would be empty.
So you need to match checkbox existence by indexing by the code value, and checking for existence more like
apex_application.g_f03(apex_application.g_f01.code)
While taking care of potential no_data_found
Reading Oracle documentation:
Note that check boxes displayed using APEX_ITEM.CHECKBOX only contain values in the APEX_APPLICATION arrays for those rows which are checked. Unlike other items (TEXT, TEXTAREA, and DATE_POPUP) which can contain an entry in the corresponding APEX_APPLICATION array for every row submitted, a check box only has an entry in the APEX_APPLICATION array if it is selected.
I've build my report referencing rownum on APEX_ITEM.CHECKBOX.
Report code:
SELECT APEX_ITEM.CHECKBOX(p_idx => 1, p_value => ROWNUM) checkb
,APEX_ITEM.HIDDEN(p_idx => 2, p_value => CUSTOMER_ID)||CUSTOMER_ID CUSTOMER_ID
,APEX_ITEM.HIDDEN(p_idx => 3, p_value => CUST_STATE)||CUST_STATE CUST_STATE
,CUST_FIRST_NAME ||' '||CUST_LAST_NAME
FROM DEMO_CUSTOMERS
And then based on that checked rows, the process is recovering the values in the hidden items arrays corresponding position.
Process PL/SQL code:
BEGIN
--
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
--
INSERT INTO ROMINA_TEST (LOG)
VALUES ('CUSTOMER_ID: '||APEX_APPLICATION.G_F02(APEX_APPLICATION.G_F01(i))||' - CUST_STATE: '||APEX_APPLICATION.G_F03(APEX_APPLICATION.G_F01(i)));
--
END LOOP;
--
END;
And it works! =)
I'm learning APEX 5
I have a control named X_CONTROL, where I want to populate his content with an SQL query.
To do that, I need the ID primary key from a table, which should be the ID of the row selected on a Select List control named MY_LIST_CONTROL.
MY_LIST_CONTROL has a list of values taken from a column of the table "MyTable", which is not the ID primary key.
I tried to populate X_CONTROL with this SQL
Select ID from MyTable where ColumnName=:MY_LIST_CONTROL
It doesn't work, and should not work because ColumnName is not "unique", like ID is.
So, the question is, how do I recover, with SQL, the ID of the selected row which correspond to the selected value in MY_LIST_CONTROL.
It should be SQL, because APEX 5 demands an SQL query to populate the X_CONTROL.
I have set up a simple example here on apex.oracle.com:
Whenever a Department is selected (item P32_DEPTNO), its Location is copied into the second item (P32_LOC).
This is done by a dynamic action on P32_DEPTNO defined as follows:
Event: Change
Selection Type: Item(s)
Item(s): P32_DEPTNO
TRUE Action:
Action: Set Value
Set Type: SQL Statement
SQL Statement:
select loc
from dept
where deptno = :P32_DEPTNO
Items to Submit: P32_DEPTNO
We are populating a subregion of a page with an Iframe (call to another page) with data for a questionnaire.
We have PAGE ITEM variables (:P37_... populated by query) that contain table values for P37_QUESTION_DESCRIPTION and P37_RESPONSE_TYPE.
The sub page used in the region (:P28_...) assigns report attributes for each column... where We populated the question text in the P28_QUESTION_DESC and a Y/N Select List defined list of values in the P28_RESPONSE_DESC_DISPLAY column. This works fine.
Now, the P37_RESPONSE_TYPE can more than just this Y/N Select List. It could be TEXTAREA, PICKLIST, DATE...
How can we define the :P28_RESPONSE_DESC_DISPLAY column dynamically to be any number of user input field types (based on the value in :P37_REPSONSE_TYPE?)
This was solved by using a non-tabular form report generated by query using apex.item functions. But is has left me with another problem. Here's the query:
select
apex_item.hidden(31,CASE_QUEST_DTL_ID) CASE_QUEST_DTL_ID,
apex_item.hidden(32,CASE_MGMT_BASE_ID) CASE_MGMT_BASE_ID,
apex_item.display_and_save(33,to_number(question_seq_no)) QUESTION_SEQ_NO,
apex_item.display_and_save(34,question_desc) QUESTION_DESC,
case when response_type = 'PICKLIST-YESNO' then apex_item.select_list_from_lov(35,response_desc,'YES_NO_SELECTLIST',NULL,'NO')
when response_type = 'TEXTFIELD' then apex_item.text(35,response_desc)
when response_type = 'TEXTAREA' then apex_item.textarea(35,response_desc,5,40)
when response_type = 'DATEPICKER' then APEX_ITEM.DATE_POPUP2(35,to_date(response_desc,'dd-mon-yyyy'),'dd-mon-yyyy')
end RESPONSE_DESC
from V_CASE_QUEST_LINK
where question_set_code like 'COB_Q%'
and case_mgmt_base_id = :P37_CASE_MGMT_BASE_ID
My problem is now grouping the questions by question_set_code. Because GROUP BY is evaluated after the select, it cannot simply be tacked on to the end of the query. I'm not sure that using a nested select will work here because of the apex.item calls. Anyone have a suggestion on how I can group these questions by the column?
I'm using Oracle Apex 4.2. I have a select list and a text field. I'm trying to create a dynamic action that should be simple enough but I'm not sure how to do it. Basically depending on what value the user selects from the list of values in the select list, the text field should then be populated. So for example:
Let's say the select list gives the user the choice to select 'Animal', 'Car', 'Person'. If the user selects 'Animal' then the text field should immediately have the value 'cat'. If the user selects 'Car' then the text field should immediately have the value 'toyota'. If the user selects 'Person# then the text field should immediately have the value 'jim' etc.
How would I make this dynamic action?
Thanks,
Stephen.
Create a New Dynamic Action with the following properties
Main Properties
Event: Change
Selection Type: Item
Item(s): [Select List]
Condition: No Condition
True Action
Action: Execute PL/SQL code
Fire When event Result is: True
PL/SQL Code:
Option 1 - use a lookup table
select LOOKUP_VALUE
into :P1_TEXT
from LOOKUP_TABLE
where original_value = :P1_SELECT_LIST;
Option 2 - Use hardcoded values
CASE upper(:P1_SELECT_LIST)
WHEN 'ANIMAL' THEN :P1_TEXT := 'cat';
WHEN 'CAR' THEN :P1_TEXT := 'toyota';
WHEN 'PERSON' THEN :P1_TEXT := 'jim';
ELSE :P1_TEXT := null;
END CASE;
Page Items to Submit: [P1_SELECT_LIST]
Page Items to Return [P1_TEXT]