Oracle Apex: Javascript code in PL/SQL Block
Is it possible to have JavaScript code in the PL/SQL block?
- YES
But, what you're trying to do wont work which is passing javascript function AFTER SUBMIT.It'll only work if you change the point of execution to AFTER HEADER.
Alternatively, if you just want to validate the values entered and doesn't want to use apex validation, you can use APEX_ERROR package.Try this.
DECLARE
v_count NUMBER;
BEGIN
select prd_items into v_count
from summary
where prd_items = 'Total';
-- I dont really know what you want to
--accomplish with this query but Im pretty sure
--It will not return a number
-- if you want to count the number of prd_items it should be like this
--select COUNT(*)
--into v_count
--from summary
--where prd_items = 'Total';
APEX_ERROR.ADD_ERROR(
p_message => 'The value of Total for BU is '||v_count||'.<br>'||
'You have to enter correct values to proceed further',
p_display_location => apex_error.c_inline_in_notification
);
END;
EDIT: if you want to show the error if count not equal to 100 then do something like this:
DECLARE
v_count NUMBER;
BEGIN
Select COUNT(*)
into v_count
from summary
where prd_items = 'Total';
IF v_count != 100 THEN
APEX_ERROR.ADD_ERROR(
p_message => 'The value of Total for BU is '||v_count||'.<br>'||
'You have to enter correct values to proceed further',
p_display_location => apex_error.c_inline_in_notification
);
END IF;
END;
To embed the javascript code from the pl/sql procedure you will have to place the procedure at a "Before Header" point. But i do not think this is the best solution for what you are trying to achieve.
What you are trying to do is to add a validation right? If so why not use the apex validations. Create a validation with options like this:
- Identify the validation level:Page Item
- Identify the Page Item that is to be validated: Select the item you want.
- Select a validation type: PL/SQL
- Pick the type of validation you wish to create:Function Returning Error Text
- Validation Code:
DECLARE v_count NUMBER; V_validation_msg VARCHAR2(500); BEGIN SELECT prd_items INTO v_count FROM summary WHERE prd_items = 'Total'; V_validation_msg:='The value of Total for BU is ' ||v_count|| '.\n' || 'You have to enter correct values to proceed further'; IF 1= 1 THEN --add some condition here if you want RETURN V_validation_msg; ELSE RETURN NULL; END IF; END;
- When Button Pressed: Your Submit button.