Hello,
Environment info:
- APEX version: 5.1.1.00.08
- DB version: 11.2.0.2.0
- Architecture: APEX listener
- Browser: Chrome 76.0.3809.132
Firstly I will describe what I want to do:
I want to let user select records by clicking checkboxes, than change one status for each selected row.
This is how I have done this:
1. I have added following column to select statement which display records in report:
APEX_ITEM.CHECKBOX2(
p_idx => 1
--,p_value => tcase.ID||'';''
,p_value => test_run_result.id||'';''
,p_checked_values => :P401_SELECTED_IDS
) checkbox
2. I have javascript event firend on change of any checkbox:
var
//Checkbox that was changed
$checkBox = $(this.triggeringElement),
//DOM object for APEX Item that holds list.
apexItemIDList = apex.item(this.affectedElements.get(0)),
//Convert comma list into an array or blank array
//Note: Not sure about the "?" syntax see: http://www.talkapex.com/2009/07/javascript-if-else.html
ids = apexItemIDList.getValue().length === 0 ? [] : apexItemIDList.getValue().split(':'),
//Index of current ID. If it's not in array, value will be -1
idIndex = ids.indexOf($checkBox.val())
console.log("idIndex: " + idIndex);
console.log("ids: " + ids);
;
//If box is checked and it doesn't already exist in list
if ($checkBox.is(':checked') && idIndex < 0) {
ids.push($checkBox.val());
console.log("First if - idIndex: " + idIndex);
console.log("First if - ids: " + ids);
}
//If box is unchecked and it exists in list
else if (!$checkBox.is(':checked') && idIndex >= 0){
ids.splice(idIndex, 1);
console.log("Second if - idIndex: " + idIndex);
console.log("Second if - ids: " + ids);
}
//Convert array back to comma delimited list
apexItemIDList.setValue(ids.join(':'));
console.log("apexItemIDList: " + apexItemIDList);
console.log("------------------BREAKE------------------");
3. I have Dynamic Action whihc is fired when the button is clicked:
declare
v_result common_result := common_result();
v_test_case_id varchar2(100);
v_test_case_id_number number;
v_test_case_version_id number;
v_count number;
v_test_run_results_ids varchar2(32000) := :P401_SELECTED_IDS;--:P402_TEST_CASE_RUN_RESULT_ID;
v_test number := 0;
CURSOR c_results_ids
IS
SELECT * from table(comma_to_table(v_test_run_results_ids));
begin
open c_results_ids;
LOOP
fetch c_results_ids into v_test_case_id;
exit when c_results_ids%NOTFOUND;
v_test_case_id_number := to_number(v_test_case_id);
v_result := pkg_test_run.UPDATE_MULTI_T_RUN_RESULT(
pi_id => v_test_case_id_number--:P402_TEST_CASE_RUN_RESULT_ID
,pi_status_id => :P401_STATUS_AFTER_CHANGE
,pi_user => :APP_USER
);
END LOOP;
close c_results_ids;
apex_application.g_print_success_message := 'Test Result updated';
exception
when others then
apex_application.g_print_success_message := 'Unexpected error uhsh: '|| SQLERRM;
end;
4. I have function which convert string generated by javascript event and return a table.
5. I use this table in above Dynamic Action and create cursor based on it, later as you can see I go throw this cursor and execute UPDATE_MULTI_T_RUN_RESULT function.
Everything is working properly, I mean that status is updated correctly for selected rows but APEX display error from above topic. I don't know how to solve it. I cannot find place where conversion from character to number occur.
Maybe someone here will see correct place.
Best Regards,
Lukasz