Oracle APEX 5.1 Custom form issue - oracle

I have a form that contains a select list (:P10_DROPDOWN) that has its values defined via SQL:
SELECT
display_name,
value_id
FROM
vw_dropdown_options;
As a pre-render-before-header-process I have the following PL/SQL to pre-populate :P10_DROPDOWN:
begin
SELECT value_id
INTO :P10_DROPDOWN
FROM vw_dropdown_option_mapping
WHERE vw_dropdown_option_mapping_id = :P10_DROPDOWN_OPTION_MAPPING_ID;
end;
At this point my form appears on my page, and everything looks okay. However I need to have a custom procedure fire when a user clicks a button, so on a button on my page I defined an onClick event to fire this pl/sql block:
APEX_DEBUG.INFO ('P10_DROPDOWN_OPTION_MAPPING_ID ' || :10_DROPDOWN_OPTION_MAPPING_ID);
APEX_DEBUG.INFO ('P10_DROPDOWN ' || :P10_DROPDOWN);
NP_SAVE_MAPPING_VALUE (
DROPDOWN_OPTION_MAPPING_ID => :P10_DROPDOWN_OPTION_MAPPING_ID,
NEW_DROPDOWN_VALUE_ID => :P10_DROPDOWN
);
This is where I first notice my issue; the value logged out by the onClick for :P10_DROPDOWN is what was originally set via my pre-render-before-header-process, and not the value I select via my drop-down.
I have tried setting the source.used value on my dropdown to both "Always" and "Only". I have also replaced my pre-render-before-header-process with a source based single value SQL query. Neither is allowing my dropdown to change the session value via the dropdown.
Am I missing something about these session values?

I suspect that this is because newly selected value isn't in session state. To test it, create a SUBMIT button, push it, and then check the result again.
Just asking: did you consider
setting item's default value (instead of writing a process to pre-populate it)
using a dynamic action (instead of creating an onClick event)

Related

Modal Dialog Form Primary Key item not refreshing in Parent Page

I am beginner in Oracle APEX (Version 22.11) and I hope, that someone can help me:
I have an Interactive Report as Parent Page. I get the data with a (simple) sql query. There is also a Create-Button, which works fine. It opens an empty Modal Dialog Form, where I can fill in the entries. There is a dynamic action, which refresh this Interactive Report by Closing Dialog.
On another page I have this Modal Dialog Form, which use the same sql query as the Parent Page and have the four button 'Cancel','Delete','Save' and 'Create'. I choose also a primary key and do different setting:
under 'Processing' I make Form - Automatic Row Processing(DML) and also Yes to 'Return Primary Key(s) after Insert
for the 'Save'-Button I have the following Behavior:
Action: Submit Page
Database Action: SQL UPDATE action
Also I have for this button the following Server-side Condition:
Type: Item is NOT NULL
Item: [Item of the primary key]
Now, I have the following problem with this Save-Button (the other buttons works fine): When I edit the Radio Button or the Textfield in this Modal Dialog Form and click the Save-Button, the Parent Page takes over the changes. But when I change the Textfield of the primary key Item or when I change another Textfield or a Radio Button together with this Primary-Key-Textfield, the Parent Page doesn't take over the changes.
Where is the mistake? Can anyone help me?
I think what happens is something else than what you think is happening. As a test I created an interactive report with a form on the EMP sample table (you can generate that in SQL Workshop > Utilities > Sample Datasets). Out of the box the report refreshes when a change in the modal form is submitted. In the modal form P102_EMPNO is marked as primary key.
No what does that mean ? It means that that page item is used by the apex engine to uniquely define the row when executing dml (update/delete) on that row.
I changed the page item P103_EMPNO to a text field, enabled debug and submitted the form. This is what debug shows:
As you can see, the where clause of the update statement is:
where "EMPNO"=:APEX$PK1
I'm assuming the bind variable :APEX$PK1 is what the apex engine has decided is the bind variable for the (first) primary key column in the form.
So... if you change the primary key, then it is NOT going to update the primary key for that row. Instead it is going to try to update a row that has the newly entered primary key value. And the refresh you're expecting is not happening... because no rows were updated.
The reason is that primary keys should never be changed during normal operation in a relational database. They uniquely define the rows - that is what a primary key does. The form region is based on this principle and the behaviour that you're seeing is expected. Also, the reason that the primary key page item is hidden or display only when a form is created is that a primary shouldn't be changed.
Now if you really want to change the primary key value (my advice: DONT. EVER.) then you can probably create a form yourself and use the rowid to identify the row. Out of the box the form region does not let you select the row id.

Filter Data block with a LOV value in Oracle Forms 10g

I need to implement a simple product form from a block of data called "PRODUCTS".
The products are related to a "Partner" through the field "COMPANIES_PARTNERS_ID".
This field will be represented by an LOV to select the Partner for which we want to visualize your products.
If there is not a partner currently selected, all your products should be displayed. And when a partner is selected, only their products should be displayed.
The form will look like this:
The button to the right of the search field should show the LOV and launch the query. I tried the following code as a "Smart Trigger" when I pressed the button. But it does not work well at all. The LOV list appears twice and when no partner is selected, no product appears.
Could someone help me to implement this functionality? Thank you
You don't need to use ENTER_QUERY command.
had better using DEFAULT_WHERE set with respect to COMPANIES_PARTNERS_ID. If not selected any of the rows of LOV by pressing CANCEL or dissmissing by X sign, then all of the products will be listed(In this case you'll see the first ID, most probably with value 1, since COMPANIES_PARTNERS_ID is not located at a CONTROL block but at the same block,namely PRODUCTS, with other items. As you go down by down-arrow you'll see the other ID values when your cursor is in COMPANIES_PARTNERS_ID field, seems that Number Of Items Displayed is set to 1 for this field, because PRODUCTS block has been set as 10 items displayed ).
So, you may use the following code in WHEN-BUTTON-PRESSED trigger :
DECLARE
V_WHERE VARCHAR2(500);
BEGIN
GO_ITEM('COMPANIES_PARTNERS_ID');
IF SHOW_LOV('COMPANIES_LOV') THEN
V_WHERE:='COMPANIES_PARTNERS_ID='||:COMPANIES_PARTNERS_ID;
ELSE
V_WHERE:='1=1';
END IF;
SET_BLOCK_PROPERTY('PRODUCTS',DEFAULT_WHERE,V_WHERE);
CLEAR_BLOCK(NO_VALIDATE);
EXECUTE_QUERY;
END;
Once you enter query mode (which is what ENTER_QUERY does), further processing is stopped until you execute query.
I presume that you created a LoV properly - the most usual way is to create a Record Group query first, and then create a LoV based on it.
Therefore, I'd ENTER_QUERY in WHEN-NEW-FORM-INSTANCE trigger and let your current push button display LoV and let user select a value into the "Companies Partners ID" item. Executing a query (either by pressing the corresponding toolbar button, shortcut key (F8?) or your new "Execute query" button) would then actually execute query. If master-detail relationship is properly created (using the Data Block wizard is the simplest option), then you'd get rows in the "Products" block.
Put a value in PRODUCTS block WHERE clause' property.
WHERE CLAUSE property:
COMPANIES_PARTNERS_ID LIKE NVL(:lov_block.COMPANIES_PARTNERS_ID, '%')

Oracle APEX default value not working on cascaded items

I have a blank page with a static content region (Template = Form Region). I select a project via a select list (there is only one project, so it automatically selects it). I then have a key popup lov (a popup lov that displays the description not the returned number value) from which I select a person to be in this project. I am trying to get the form to display the person I selected and saved previously when the form launches for the first time (since the project is chosen due to there being one). This works when you refresh the page, but it doesn't work if you log out and log back into the form. I tried using the default value with a sql query. I tried using a dynamic action that fires when the project changes; but neither approaches work. I fiddled with all the settings, but couldn't get anything to work. Does anyone know how to accomplish this in Oracle APEX?
I even added a refresh of the cascading popup lov to the dynamic action. I can see the hidden input item showing my defaulted value, but the popup lov does not display it on screen. Is this an Oracle bug?
Also in Javascript from the console
$s("P51_LINE_MANAGER1", "7104");
sets the hidden value, but doesn't display on screen.
$v("P51_LINE_MANAGER1");
does however return 7104.

Oracle APEX How to submit page with PL/SQL insert/update and then transition to next page

I have an Oracle APEX page that collects data via a classic report with apex_item dynamically generated items. Something like this:
select apex_item.radiogroup(qt.save_position, 1, qt.answer, null, null, null, null) col01
from xxpay_360_questions qt
where qt.questionnaire_id = 21
I then save the answers using a submit button that uses "Submit Page" and calls PL/SQL to insert/update the dynamically generated items from above. Something like this:
insert into xxpay_360_answers values (apex_application.g_user, APEX_APPLICATION.G_F01(1));
commit;
My question is how can I also do a transition to the next page of dynamically generated items (since I only have 50 apex variables to play with per page) when the submit button is clicked.
The submit button only has options for "Submit Page" and "Transition to Page" and not "Submit Page and then Transition to Page".
Is there a way of transitioning via PL/SQL as part of the submit code? Or is there an event that can transition after the page has been submitted?
Also how does this work with errors and the nice "Saved" fly over that apex has?
You need to create a Branch, on the after processing region:
Then you need to set as branch point: On Submit After Processing (After Computation, Validation and Processing) and the branch type as: Branch to page
Then specify the page number where your going to:
And finally you can set the branch to be fired only if one particular button is pressed and if one particular condition evaluates to true:
I think that would cover your needs.
But if you want to do it with PL/SQL you could do something like this:
Replace the page ID with the actual page Id to which you want to redirect the user.
BEGIN
IF(CONDITION)THEN
htp.init;
owa_util.redirect_url('f?p=&APP_ID.:10:&APP_SESSION.'); /*Replace 10 with actual Page Number*/
apex_application.stop_apex_engine;
ELSE
htp.init;
owa_util.redirect_url('f?p=&APP_ID.:20:&APP_SESSION.'); /*Replace 20 with actual Page Number*/
apex_application.stop_apex_engine;
END IF;
END;
Or you could use the APEX_UTIL.REDIRECT_URL procedure.
if you are using APEX 4.2 refer the APEX_UTIL reference from here.
You can use:
apex_util.redirect_url(
p_url => 'type your url here'
);
This effectively calls in the owa_util. redirect_url and automatically calls apex_application.stop_apex_engine.

Populating a text box from from the value in a drop down

I'm creating a form in apex where I want to populate a text box with a value which has been selected in a drop down box. This needs to be done using a select statement on the form.
I have tried using a Dynamic action.
If I was using SQL I would pass the value of the id which I have retrieved using a combo box.
SELECT APPLICATION_ID FROM APPLICATIONS WHERE JOBID = :P55_JOBID
this would update my APEX field (P55_APP_ID)
P55_JOBID is the Job ID APEX field.
The Select statement for APP_ID works but I want it to be updated when the Job Dropdown list changes. I've been told to use a Dynamic action but I cant work out how it triggers a refresh of App_ID..
thanks for your help,
mike
Thanks for your help.
You want a dynamic action that is triggered on the Change event of the select list (P55_JOBID). The action of this will be Set Value and the Set Type will be SQL Statement. Add your SQL (SELECT APPLICATION_ID FROM APPLICATIONS WHERE JOBID = :P55_JOBID) here and then under Page Items to Submit include your select list (P55_JOBID).
The Selection Type will be Item(s) and the Item(s) will be your text area (P55_APP_ID).

Resources