ORACLE APEX Question on using Update / Save Button - oracle

I've created an APEX page based on a single table, which is then called by a another APEX page with a field value to be queried.
The page displays the record, which has a Primary Key consisting of 2 fields.
When I use the Update/Save button, it appears not to update the data, though it does not return any errors.
This works OK on other APEX pages where they are based on Tables with a single field Primary Key.
I would appreciate an explanation/solution from anyone who has had a similar problem and found a workaround.
Thanks in advance

Your page should have a "Process Row of MYTABLE" process. Have a look in the details of the process, you'll find that it has the following attributes:
Item Containing Primary Key Column Value
Primary Key Column
Item Containing Secondary Key Column Value
Secondary Key Column
Your process should include both Primary and Secondary Keys.

Related

How to use Oracle APEX dynamic action to populate a 'form on a table' field on the basis of other fields and underlying sequence?

I am implementing a 'form on a table' that will allow the end-user to create records in the database. I would like to generate the primary key for the underlying table based on the selections the user makes as well as the underlying sequence.
The basic formula for the primary key should be a concatenation of the 'disposal site code' + 'year of study' + str(sequence). The sequence is should start at and increment by 1 so that the first project created in the database end with -1 and the nth with -n.
For example if the user selects the 'Disposal Site' as 'Seldom', the field 'Disposal Site Code' should be dynamically populated by 'CA-AT-D130' (a 1:1 code alphanumerical code for each site) and after selecting the year, for example 2022, the project number would dynamically be populated as CA-AT-D130-2022-01 (assuming first entry in the table). After creating the new record CA-AT-D130-2022-01 would become the 'project number'.
Can anyone recommend the idiomatic way to do this in APEX? I have a feeling what I am needlessly complicated something that should be relatively straightforward.
There are 2 ways of doing this that are a lot simpler than what you are trying. There is no reason at all to use a dynamic action, this can just be done using apex page processing.
option 1: in the database: Create an trigger on the table that sets the primary key column based on the other column values & sequence
option 2: in apex: Create an after submit computation on the page item to compute the value based on the other page item values & the sequence.
option 3: what I would do instead:
In my personal opinion this isn't a good option for a primary key. The primary key should just be a unique row identifier with no business value. Just use an identity column for that and no additional work is needed in db or apex.
Sounds like you want to capture business information in the key. Well... make that a "pseudo-primary key" and store that information in a column with a unique index in your database. Or, use a virtual column in your table that calculates this value from the primary key column and the other columns you need.

Form WHERE clause

I have an APEX form I'm developing for "user settings". I have a table with a sequence as a primary key and the users ID in another column...in addition to a few columns where each users saved settings are stored (things like "N" for do not receive notices).
I haven't used Oracle APEX in a while so excuse this likely newbie question...The insert works fine, but I'm having trouble with making the form only show the current users values. In my Form Region the source is set to my Table, and I have a WHERE clause like this:
USER_ID = 813309
But that's not working (813309 is my id and I'm just hard-coding it for now). The form always comes up with a "New" record.
For a form to load a specific record you can set the primary key page item to the value you need. You can do so in the url using the link builder from another page or you can set a computation on the item. That is what I would try in your case: add a computation to your item P_USER_ID of type "Static Value" with value 813309. Make sure the computation happens before the "Fetch Row" - the value obviously needs to be set before the process runs.
In such cases, I prefer creating a Report + Form combination (using the Wizard, of course): it creates an interactive report (so that you can review data in a table), and a form which is used to add new records or update/delete existing ones.
Doing so, when you pick a user in interactive report and click the icon at the beginning of a row, Apex redirects you to the form page, passing primary key column value to the form which then fetches appropriate data from the table.
Not that it won't work the way you're trying to do it, it's just simpler if you let Apex do everything for you.
So: did you create an automatic row fetch pre-rendering process? If not, do so because - without it - Apex doesn't know what to fetch. Also, if you hardcoded user_id, it won't do much good. Consider storing username into the table so that you could reference it via :APP_USER Apex variable.

DATA_LENGTH_0 in maintenance view

I created a view for a client-independent customizing table. The primary key consists of three components - first one being a secondary key on a check table. It is also used to form subsets of the table data. Altogether, it looks something like this:
Column Key
------ --------
frmd Secondary check table and Subset
attr1 KEY
attr2 KEY
url
But everytime I try to insert a new key combination, the view dumps with DATA_LENGTH_0 CX_SY_RANGE_OUT_OF_BOUNDS, because the report tries to access a string. Apparently it is somehow related to the field generictrp being set. What does this flag tell me and how do I change it? Also non-key components like url are not being fetched - the column is totally empty.
Modifying the customizing table via transaction SM30 works fine, but I don't want that ugly first column.
I've tried to recreate the view multiple times and I also compared the settings with existing customizing views.
Access is set to read,change, delete and insert
Display/Maintenance is allowed
Selecting everything from the View with SELECT works fine
EDIT
Picture 1: what I have
Picture 2: what I want; without the first key column...
The most likely reason I faced this problem, is that I had a foreign key of type i. I changed the type to n and regenerated everything.
Seems to work for now.

Any way to intercept an error message and make more user friendly?

I have looked for an answer here among other places but havent quite been able to find what I need to know.
I have 3 tables, Order_Details, Products_Ordered and Product_Details. The first two are being used in a master detail form to show the order and the items ordered together. The Products_Ordered table has a composite primary key made from two foreign keys, the first being the primary key from the Order_Details table, and the second being the primary key from the Product_Details table. Together they ensure that a type of product can only be added to an order once. If someone wants to order more than one product then the quantity field in the record can be altered to reflect this. All that seems fine so far.
My issue is that when adding products to the order in the master detail form i have used a drop down list of values to select the product to add to the order. the display value for this is the product name and the return value for it is the primary key for the product from the Product_Details table.
I like this because its easier for the user to simply select the product and add a quantity of it to the table. And it works fine for both insert and update operations apart from one situation.
If the user selects the same product in to rows then submits the table the database then tries to add the product to the order twice, throwing a "ORA-00001: unique constraint violated." error. Obviously this is because of the product ID being used in the primary key of the table.
I don't want to allow the user to add two records to the table like that, rather id like to force them to alter the quantity field accordingly. The error message that comes up isn't very user friendly so my question is how can I detect this error and display a more user friendly one instead telling them to alter the quantity field instead?
*If this isn't possible then is there a way that I can hide any already selected products from the dropdown list of values in the following table rows? I haven't looked into this too much because surely it would get complicated when the user tries to add more rows than products available in the dropdown and there are no more products values to show?
I am quite new to this so please be nice. Any help is greatly appreciated :D
Here is a link where all is nicely described:
https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm
Section
Predefined PL/SQL Exceptions
in combination with:
Defining Your Own PL/SQL Exceptions
and
Defining Your Own Error Messages: Procedure RAISE_APPLICATION_ERROR
Hope it helps...

"Record has already been inserted" on commit in Oracle Forms 6i

I'm not an Oracle forms guy, but I'm stuck maintaining an old Oracle Forms 6i app that our company has, so I apologize if I sound like I don't really understand forms, because I don't.
We have a pre-existing form that I've had to make some change to. It has a master/detail type setup. There are a series of "rows" for the details. When I enter master info and the first detail record, I can save just fine. When I add a second row of info to the details section, it gets to the KEY-COMMIT trigger, but when it actually hits the "commit;" line, it gives me the error "Record has already been inserted."
But there is only the one record associated with the master details in the table. When I clear that message it asks, "Do you want to save the changes you have made?" If I click "Yes", it just gives me the "Record has already been inserted" message in the status bar and nothing happens. If I try to exit the form, it again asks if I want to save the changes, but "yes" does nothing but keep me on the form. Clicking "No" removes the second detail record.
I'm confused. I'm clearly missing something.
Your detail data block has the Enforce Primary Key property set to Yes. It means that rows inserted/updated/deleted by this block are not queried by rowid, but by primary key.
It does not matter, how is primary key set in database, but how is set in forms. Check all items in your detail block and find those with Primary Key (Item) property. Then check, if there is a duplicate record in database.
I prefer using rowid and uncheck Enforce Primary Key property. If your block works directly with database table (not view), it works fine

Resources