Classic report SQL:
SELECT APEX_ITEM.HIDDEN(10,Q.QUESTIONID) QUESTIONID_HID,
Q.QUESTION,
CASE WHEN Q.ANSWER_TYPE = 'RADIO' THEN
CASE (SELECT LISTAGG(A.ANSWER_CODE, ', ')
WITHIN GROUP (ORDER BY A.ANSWERID, A.ANSWER_CODE) ANSWER
FROM XYZ A
WHERE A.QUESTIONID = Q.QUESTIONID)
WHEN 'G, P' THEN
apex_item.radiogroup(20, 'G', NULL, 'Government')||'<br>'||
apex_item.radiogroup(20, 'P', NULL, 'Private')
WHEN 'L, H, M' THEN
apex_item.radiogroup(30, 'L', NULL, 'Low Income')||'<br>'||
apex_item.radiogroup(30, 'H', NULL, 'High Income')||'<br>'||
apex_item.radiogroup(30, 'M', NULL, 'Medium Income')
END
ELSE
APEX_ITEM.TEXT(20, NULL)
END INPUTCOL
FROM ABC Q
WHERE Q.APPID = :APP_ID;
And my page level process:
DECLARE
V_QUESTIONID INTEGER;
V_ANSWER_OPT VARCHAR2(20);
V_ANSWER VARCHAR2(20);
V_ANSWER_TYPE VARCHAR2(10);
BEGIN
FOR i in 1..APEX_APPLICATION.G_F10.COUNT LOOP
V_QUESTIONID := APEX_APPLICATION.G_F10(i);
SELECT Q.ANSWER_TYPE INTO V_ANSWER_TYPE
FROM ABC Q
WHERE Q.QUESTIONID = V_QUESTIONID;
IF V_ANSWER_TYPE = 'RADIO' THEN
SELECT LISTAGG(A.ANSWER_CODE, ', ')
WITHIN GROUP (ORDER BY A.ANSWERID, A.ANSWER_CODE) ANSWER INTO V_ANSWER_OPT
FROM XYZ A
WHERE A.QUESTIONID = V_QUESTIONID;
END IF;
IF V_ANSWER_OPT = 'G, P' THEN
V_ANSWER := APEX_APPLICATION.G_F20(i);
ELSIF V_ANSWER_OPT = 'L, H, M' THEN
V_ANSWER := APEX_APPLICATION.G_F30(i);
ELSE
V_ANSWER := APEX_APPLICATION.G_F20(i);
END IF;
INSERT INTO CSD_DTL (CSDID,
QUESTIONID,
ANSWER,
CUSTOMER_POINT)
VALUES(:P10_SURVEYID,
V_QUESTIONID,
V_ANSWER,
10);
COMMIT;
END LOOP;
END;
This code works fine for 4 rows one radio group and 3 text field but when loop goes for 5th row which have another radio group then it gives error. Get classic report column value by APEX_APPLICATION.G_F01(i) this is not new for me but here in this case I used two radio group in same column but different rows with different codes one is apex_item.radiogroup(20, 'G', NULL, 'Government') and oter is apex_item.radiogroup(30, 'M', NULL, 'Medium Income') because with same codes radio button not works, accept answer in only one. My requirement is to take user response in selectable options in some questions & in text fields for some questions. Please help if any one can solve this problem.
The function APEX_ITEM.RADIO_GROUP
creates a single radio group for the entire report. It is meant for the use case where a user needs to select one row from the report. It cannot be used to create a radio group per row. As you have seen, that renders fine but you can only select a single value over the entire report. Use APEX_ITEM.SWITH
(if only 2 values) or any of the APEX_ITEM.SELECT_LIST_%
functions for a per row selection.