Hi, I’d been implementing the tutorial for adding Add/Del/Save buttons to a interactive grid (https://www.foxinfotech.in/2019/10/oracle-apex-interactive-grid-create-custom-add-edit-save-and-delete-buttons.html ) using Dynamic Actions which now works well. However I have a couple of questions/issues that I hope you’ll be able to help with.
- When I add a new item to my grid, I need to check that that item doesn’t already exist, and
- When I delete an item, I need to run some PL/SQL to check another table to see that that item is not used there.
In both issues, I can create the core code but I just need to know how I can access the various items on the page and pass them through to the DA execution item to prevent/allow the action accordingly. TIA Martin
Hi Martin,
You can handle the first issue by following these steps:
Below examples, I am giving on the Employees table. My interactive grid having the following columns EMPLOYEE_ID, EMPLOYEE_NAME, etc.
Create one hidden item, for example, P12_EMPID, and turn the value protected property off.
Create a dynamic action on EMPLOYEE_ID on change event.
Create a True action as Set Value and set the following properties:
Create one more True action as Execute JavaScript code below the above action. Add the following JavaScript code in it:
The above JavaScript code will call the Ajax process validate_empid by passing the P3_EMPID, which we are going to create now.
Click on the Process tab > Ajax Callback. Do right-click on it and select the option Create process. Set the following properties of it:
Now save the changes and run the page. Now if we will enter the employee id which already exists, it will give the error message using a dialog.
But this message is just to give an alert, you still have to write a validation to prevent the save duplicate employee id. Follow these steps to create the validation.
Do the right-click on the Employee_ID column in the interactive grid and select the option Create Validation and set the following properties:
and rowid != nvl(:crowid, ‘0’)
Note: You should take the ROWID column in your interactive grid and rename as CROWID, so that you can use in the above validation query.
Now you know, how to create a JavaScript server process to call the Ajax callback process.
For the 2nd issue, you can create another Ajax callback process to check if the employee id exists in other tables or not. Call it using the JavaScript server process.
Hi Vinish
Ouch! Didn’t realise it would be like that but many many thanks. This will help in increasing my understanding of Apex and how it all hangs together.
I’ll let you know if I’ve understood it properly.
Hi Vinish
I just wanted to update you on the progress of this task. I’ve managed to implement my second requirement, solving a couple of issues on the way. It may not be the same solution that you may have proposed but very similar.
I wanted to check for a value that was already being used in another table so activated the Ajax code on the Delete button, having set a page item of the ROWID on the selection change of the region. All worked well except where I’d added a duplicate item of one that was being used in the other table, and then tried to delete the new item. The Ajax code ran because I was deleting something.
So, because the new item hadn’t been submitted to the database, its RowID was set as a temporary one (t1000 etc.), I was able to trap this and therefore delete it without checking about it being used in the other table.
So, thanks again for your help.
Martin
Hi Vinish,
Many thanks for this. I’ve implemented the first issue successfully after missing the colon in the Expression of the Set Value and the typo in the text, where passing P12_EMPID instead P3_EMPID 🙂
I’m having trouble implementing the second part although I understand what’s to be done. I’m going to preserver and will get back to you if I get stuck.
Thanks again. I bow to your knowledge!!
Martin
Thank you so much Martin, you are always welcome.
You try the second issue and let me know if any issues.
Hi Vanish,
how can i do follwoing when i have three apex items like P1_DR , P1_CR and P1_AMT
2. If user enter some values in P1_CR then P1_DR becomes unwriteable and and P1_AMT got the value of P1_CR.