Get the values of the selected rows with checked checkbox - oracle-apex

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! =)

Related

How to ajax refresh a region in ORACLE Apex - based on a selection in a Badge List [Plugin]

I have a badge list plug in returning a few items:
SQL for the badgel list plug-in is below:
WITH
STUDY_MV AS
(
SELECT /* MATERIALIZE */
* FROM VW_GRET_CTA_STUDIES
WHERE GRET_ID = :P14_GRET_ID
AND STUDY_CODE = :P14_STUDY_CODE
AND VARIATION_REQUEST_ID IS NULL
AND APPLICATION_TYPE = 'Clinical Trial Application'
)
select
'1) Despatched CTA' as label,
(SELECT COUNT(DISTINCT REGISTRATION_UID) FROM STUDY_MV
WHERE
STUDY_STATUS = 'Despatched'
) as value,
'Despatched' AS STUDY_STATUS,
APEX_PAGE.GET_URL (
p_page => 15,
p_items => 'P15_GRET_ID,P15_PREVIOUS_PAGE,P15_STUDY_CODE,P15_STUDY_STATUS',
p_values => :P14_GRET_ID || ',14,' || :P14_STUDY_CODE || ',Despatched') as url
from dual
UNION
select
'2) Submitted CTA' as label,
(SELECT COUNT(DISTINCT REGISTRATION_UID) FROM STUDY_MV
WHERE
STUDY_STATUS = 'Submitted'
) as value,
'Submitted' AS STUDY_STATUS,
APEX_PAGE.GET_URL (
p_page => 15,
p_items => 'P15_GRET_ID,P15_PREVIOUS_PAGE,P15_STUDY_CODE,P15_STUDY_STATUS',
p_values => :P14_GRET_ID || ',14,' || :P14_STUDY_CODE || ',Submitted') as url
from dual
This works...
I was originally using the URL to go to another page (page 15), and was passing parameters to it...but I now need to do a refresh (ajax/dynamic action) of another region on the same page based on the selection in the badge list. i.e. if they click the "Submitted" bage, then an interactive grid on the same page gets refreshed over ajax to only show "Submitted" records).
The interactive grid has the following SQL:
SELECT
DISTINCT
reg_flag_passive,
study_status,
registration_uid,
application_stage,
application_type,
lu_withdrawn_dt,
country_display_label,
authorization_status,
registration_name_details,
registration_number,
reg_remarks,
region,
preferred_trade_name,
lu_despatched_dt,
LU_SUBMITTED_DT,
lu_resubmitted_dt,
lu_approved_dt,
lu_non_submission_approval_dt,
lu_approved_inc_non_sub_year,
lu_approved_inc_non_sub_dt,
lu_cancelled_dt,
lu_report_due_dt,
lu_rejected_dt,
lu_planned_submission_dt,
LU_EXPECTED_APPROVAL_DT,
cta_ind_no,
study_code,
gret_id
FROM
vw_gret_cta_studies WHERE STUDY_CODE = :P14_STUDY_CODE AND GRET_ID = :P14_GRET_ID
AND VARIATION_REQUEST_ID IS NULL
AND APPLICATION_TYPE = 'Clinical Trial Application'
AND
1 = (CASE WHEN :P14_STUDY_STATUS IS NULL THEN 1 ELSE CASE WHEN STUDY_STATUS = :P14_STUDY_STATUS THEN 1 ELSE 0 END END)
What I need to do is POPULATE the :P14_STUDY_STATUS page item, to session, with the selected STUDY_STATUS value clicked within the badge-list plug in, and then perform a refresh of the interactive grid region - which will pick up the :P14_STUDY_STATUS value in the query.
I am guessing that in order to write things into session via javascript, and then refresh a region (e.g. call a dynamic action to do it) - then I need to perhaps modify the URL I am generating in the badge list SQL to make a javascript call? But having no luck at all.

exercising ARP on a page with plenty of items

I have an apex form composed of around 50~ text fields and radio buttons.
I tried to create a page process for automated row processing. It works fine but only if my table has a column for each page item.
even though the page items are plenty, actually the question behind them is the same. So what I really want to perform is to collect those data row by row. i.e.
instead of
1 True False True foo
I'd like to store my data like this
1 True foo
2 True goo
3 False hoo
50 False zoo
Since I couldn't find a way to customize ARP, I decided to do it with some manual work.
However I still have this feeling that my efort is futile. I can't help but thinking there must be some other, wiser solutions than being have to create insert/update statements for entire page. I mean I can't be the only one who came up with this need, right?
Thank you very much in advance.
I hope you can achieve your requirement using APEX_COLLECTION. It stores the data temporarily that are associated with the session of the user currently logged into the application. below is the sample code for your reference.
begin
if not apex_collection.collection_exists('SAMPLE_COLLECTION') then
APEX_COLLECTION.CREATE_OR_TRUNCATE_COLLECTION(p_collection_name => 'SAMPLE_COLLECTION');
apex_collection.add_member(
p_collection_name => 'SAMPLE_COLLECTION',
p_c001 => :P1_TEST_ITEM1,
p_c002 => :P1_TEST_ITEM2,
p_c003 => :P1_TEST_ITEM3,
p_c004 => :P1_TEST_ITEM4,
p_c005 => :P1_TEST_ITEM5,
);
end if;
end;
You can select the data stored using the below SELECT statement.
select c001, c002,c003,c004, c005
from apex_collections where collection_name = 'SAMPLE_COLLECTION'
Please refer this link to explore more on APEX_COLLECTION

Select list display issue

Good morning,
within Oracle Apex Application Builder I'm trying to create a order product page which displays products from a product table, shows a select list which a user can use to define the quantity in which they want to order. Using a classic report to display my code, the declared table columns were generated and outputted on the report, however the select list column only shows the html syntax used to create a select list and not the actual drop down select list with values.
Here is the code:
select p.product_id,
p.product_name,
p.product_price,
apex_item.hidden(1, p.product_id) ||
apex_item.hidden(2, p.product_price) ||
apex_item.select_list(
p_idx => 3,
p_value => nvl(c.c003,'Add_to_cart'),
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') "add_to_cart"
from prod p, apex_collections c
WHERE c.collection_name (+) = 'ORDER_ITEMS'
and c.c001 (+) = p.product_id
Can someone explain why this is happening, how to correct my issue and if there are better ways to implement a select list; as I need this code to work for my project?
Thanks in-advance for the help!
In Builder, navigate to that column so that you'd see its properties. Scroll down to Escape special characters and set it to "No". Then run the report and see whether there's any improvement (should be).

apex select list, get user data

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>

Update cell of APEX_COLLECTION in interactive grid

I have a interactive grid with a full join on the wwv_flow_qb_saved_query table and the apex_collection, like this:
Select
qbsq.ID,
qbsq.TITLE,
qbsq.QB_SQL,
qbsq.DESCRIPTION,
ac.collection_name,
ac.seq_id,
ac.C001 as new_TITLE,
ac.CLOB001 as new_QB_SQL,
ac.C002 as new_DESCRIPTION
FROM APEX_050100.WWV_FLOW_QB_SAVED_QUERY qbsq
full join apex_collections ac
on qbsq.TITLE = ac.C001
The result look like this:
Now I need to make the possibility for users to change the title of the apex_collection, so the title in the "imported queries" column group. If the title is updated and different from the title of the existing queries, there would be a new grid entry.
I tried to do it in the "save interactive grid data" process => settings => target type => pl/sql code with
declare
collection_name varchar2(255);
seq_id number;
new_title varchar2(4000);
begin
collection_name := :COLLECTION_NAME;
seq_id := :SEQ_ID;
new_title := :NEW_TITLE;
case v('APEX$ROW_STATUS')
when 'U' then
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE (
p_collection_name => collection_name,
p_seq => seq_id,
p_attr_number => 1,
p_attr_value => new_title);
end case;
end;
But something just doesn't work and I can't change the title. Am I missing something? Please could someone help me find the problem. I couldn't find any other helpful posts..
Thanks
Thanks to Tony Andrews, for the solution I just had to change in the regions attributes the "Allowed Row Operations Column" to "null".
WHy are you using collection? With IG you can modify data , change the pagination and return to the previous pagination , all your change will be there.