I have a button in my 20.2 apex application and I want it to only run PL/SQL code if two page items both have a value. If I was only checking one page item, I could create a dynamic action with true and false actions based on an ITEM IS NOT NULL condition. How do I extend this to validating 2 items, each with a separate error message.
Share
suppose your item is p1_item1, p1_item2
validation– PL/SQL Function Body Returning Error Text
begin
if :p1_item1 is null and :p1_item2 is null then
return ‘both item should not empty’;
elsif :p1_item1 is null and :p1_item2 is not null then
return ‘p1_item1 should not empty’;
elsif :p1_item2 is null and :p1_item1 is not null then
return ‘p1_item2 should not empty’;
end if;
end;
—replace error message as your requirement
Always Execute===> yes
Looking around, I see that you mean to add a page-level validation which validates 2 items.
I have 2 buttons. One button requires only one field to be filled. The other requires both fields. Would it not be better for each field to validate itself, with the validation code dependant on the button pressed? If so, how do I know which button was pressed?
create validation as show in below
The image is too low-resolution to read properly, but I think I have worked out what you are saying. In the Processes tab, I can create a validation routine which is only applied when a specific button is pressed. I can therefore create a validation routine for each button.
Thanks.
I finally got around to trying this but it still did not work. I think the problem is I am not submitting the page, but issuing explicit PL/SQL code to update the database. I have now tried 2 other options posted by Vinnish (Oracle Apex Validation Without Submit Using JavaScript and Ajax Callback) but they did not provide joy either.
The current situation (using Vinnish’s AJAX method) is that the buttons return an error message saying that it cannot insert the record with a null value for such and such column (standard ORACLE error message), THEN it displays the user-friendly error message, even though the actions generate the user-friendly message before it tries to insert the record.
The second action performs the insert.
How do I get the first action to abort on error?
Postscript: I have made this work by changing the INSERT code so it only attempts an INSERT if the 2 items are not null. That way, I only get to see the user-friendly error message.
Is there a neater way of doing this?