Is it possible to have JavaScript code in the PL/SQL block. I want to execute the pl/sql block containing JavaScript code on submit in oracle Apex page process.
DECLARE
v_count NUMBER;
BEGIN
select count(*) into v_count
from summary
where prd_items = 'Total';
HTP.p ('<script type="text/javascript">');
HTP.p ( 'alert(''The value of Total for BU is ' ||v_count|| '.\n'
|| 'You have to enter correct values to proceed further \n'');');
HTP.p ('</script>');
END;
I have Submit
button in my page region and this pl/sql block is page processing item and execute on page submit(Conditional:Submit
).
But I am not able to pop-up the alert box. Please advise.
Thank you.
Is it possible to have JavaScript code in the PL/SQL block?
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:
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With