Dynamic action is not trigger if i will put the LOV select list value in where condition on click button event - oracle-apex

I am selecting a value from LoV.Then i am clicking a button to trigger dynamic action(When->event=click,selection type->Button,Button name).Then in Server-side Condition i am putting (rows return->select * from tab)--Its triggering as expected,But if i will change sql query (select * from tab where col=:Lov)(there is 1 record,but its not triggering).

The reason why it is not triggered, is because a server-side condition tells APEX whether or not to load the defined Dynamic Action when rendering the page.
In your first example, the query select * from tab will return rows. So when rendering the page, the dynamic action will be loaded and executed when the button has been pressed.
In your second example, including the where clause select * from tab col=:Lov, page item :lov is most likely still empty when rendering the page and therefore the dynamic action is not being loaded and doesn’t exist for the browser at the moment you press the button.
Server-side condition is not the right solution here.
If you want the dynamic action only being executed when the selected lov item also exist in a table.
In APEX 5.1 you can execute an AJAX call in your DA to check the row existence before executing the actual logic.
In APEX 19.2 you can define extra output columns in a LOV, which you can use to set an additional page item. Set that item as an indicator (Y/N) to run the DA. Then you can use the Client-side condition to determine whether or not the DA should be executed, based on the indicator.
Hope this helps. Let me know when you need further assistence with one of the two solutions.

Related

How to add a new record into an interactive grid using IG methods then set column's value using $s() api?

I am using Oracle Apex 18.2.
I have an interactive grid and a custom button to add a new row to the IG using,
apex.region("myRegionStaticId").widget().interactiveGrid('getActions').invoke('row-add-row'); then set a column's value using, $s("myColumnStaticId","2");. When I try it, it adds the first row without setting any columns' values and starts setting the value from the second row on. Even using selection-add-row or insert-record, there is always something with the first row. Here is a sample,
[https://apex.oracle.com][1]
ws = ESLAM_WS
user = forhelp
pwd = forhelppwd
app = TEST
page = Add Row on top of an IG.
After a lot of talking and testing, I've found that $s with setTimeout isn't very reliable. I've set up page 7 again to demonstrate.
If you click the Rowaddrow button twice in rapid succession (the second time before the first setValue returns), the second row will not be initialized. I'll show you a workaround for this below, but you'll
If you lower the setTimeout to, say, 10 ms, and try focusing in the Expiry Date column before clicking the Rowaddrow button, you'll find it doesn't work. This means that, while the setTimeout of 100 ms works now, it could break in the future if the IGs internal logic changed. Unlikely but who knows.
For the moment, I would say that $s can only be reliably used to set a column value in an IG for the active row. When the row-add-row action adds a new record, it does make it active, but that is done asynchronously via setTimeout. This is because the IG is based on the flyweight pattern and there are a number of async (setTimeout based) heuristics that are built in to handle focus and blur events to correctly enable and disable rows and cells as needed.
I've found the following to be the most reliable solution. Unfortunately, it's more complex than what you had before - but it was the only way I could wrangle it all together. Feel free to use it or not. See page 8 for an example.
Right-click the custom Rowaddrow button and select Create Dynamic Action. Set the Name of the DA to rowAddRow button clicked. The When settings will automatically be configured for the click event on the button.
Select the action for the new DA. Set Action to Execute JavaScript and enter the following JavaScript in the Code attribute.
addRowClicked = true; // Global used to distinguish custom button click
this.triggeringElement.disabled = true; // Disable button to serialize access
apex.region("KITCHEN_SHARE_DTL").widget().interactiveGrid("getActions").invoke("row-add-row");
Create a new Dynamic Action and set the Name to New row initialized. In the When section, set Event to Row Initialization [Interactive Grid], Section Type to Region, and Region to KITCHEN_SHARE_DTL.
Under Client-Side Condition, set Type to JavaScript expression and enter the following code in JavaScript Expression (which ensures the DA only fires for the click of the Rowaddrow button):
addRowClicked === true
Select the action for the new DA. Set Action to Set Value, Set Type to Static Assignment, and Value to 2. In Affected Elements, set Section Type to Column(s) and Column(s) to INGREDIENT_ID. This will replace the static assignment that was being done with $s. Ensure that Fire on Initialization is disabled.
Right-click the True branch for the DA and select Create TRUE Action. Set the Action to Set Value, Set Type to SQL Statement, and enter the following code in SQL Statement:
select MIN(EXPIRY_DATE) from stock
where ingredient_id = TO_NUMBER(:INGREDIENT_ID);
Set Items to Submit to INGREDIENT_ID and disable Escape Special Characters. In Affected Elements, set Selection Type to Column(s) and Column(s) to EXPIRY_DATE. Ensure that Fire on Initialization is disabled.
Right-click the True branch for the DA and select Create TRUE Action. Set Action to Execute JavaScript Code and enter the following JavaScript in the Code attribute.
addRowClicked = false; // Unset the global
$x('ADD').disabled = false; // Enable the button
Change the following code:
$s("INGREDIENT_ID","2");
with the following one:
setTimeout(function(){ $s("INGREDIENT_ID","2"); }, 100);
It seems that the IG needs a little time to render the new row before you are able to change any value.

Oracle Apex dynamic action not firing on true condition

I have a page with two Interactive Grids. One shows Approved records. One shows Unapproved records. There is a button with processing underneath on each grid to set the selected rows to Approved/Unapproved respectively.
I want to hide these buttons based on if a user is an Approver. These values are store in some user managed tables.
I have a dynamic action on Page Load that runs the following and sets a page item to 1 / null depending on the return:
select 1 from users where upper(username) = upper(:APP_USER) and userrole = 'APPROVER';
Based on the value in the page item two dynamic actions fire on page load to set the buttons with
True=Show
False=Hide.
Client Side Condition: Item = Value: P1_PAGE_ITEM = 1
Now - on my local machine this works fine. I made the page item visible. Can see a 1 or null and the buttons are hidden/shown.
I moved this to a Development environment and now I get a warning about Unsaved Changes each time I click out of the page (doesn't happen on Local). And although I can see a 1 in the Page Item field the actions see this as False (I put an alert on to fire when true/false).
Question is: Why am I getting the unsaved changes warning on the new environment. And why would the actions see the field as FAlse.
I have compared all of the properties as best as I can and they seem identical. I have even arranged the sequence numbers to be identical in the two environments.
All thoughts welcome...
This doesn't need to be a DA that is modifying a field value, hence the alert.
Why not define a computation that executes during the render, and use that as a server side condition on your Dynamic Action?
Otherwise you've enabled a security threat, where the user can tweak some HTML to see the regions you've hidden.

Oracle APEX - Transferring page item value from one page to another

Not sure what am I doing wrong and need help to diagnose the issue.
I have an apex page with an IG on it with radiobutton selection column, allowing the user to select only one row at a time.
On row select I use javascript to grab the ID of the selected row and then use Execute PL/SQL
NULL;
in order to store the value into the session state of P2_ID.
I also have a button on the page that has another page as a target - page 3, and I need to get my P2_ID value to that page.
So I set the page item of a target page - P3_ID ro &P2_ID. in a Link Builder - target pop up window. Along with that I pass another page item P2_TEST, which has a static value.
Now when I get to page 3, I do not see P3_ID in the session state while I do see P3_TEST and it does have a value, but P3_ID is not even listed... What am I doing wrong here?
How about this: instead of executing NULL; when pushing the button, SUBMIT (submit will certainly store values into session state). Create a branch which takes you to page 3; among branch properties, you'll find an option to set P3_ID to P2_ID

Oracle APEX, create & save (insert) from Interactive Report page to DML Form

Need a help in understand underline logic here. I have created a simple APEX application. First page shows the table details and via a "Create" button "Interactive Search" region, directs to a form page. Now form page consists of "Save" and "Insert" buttons in correct regions. So whole app works. When I press "Create" from 1st page to 2nd, "Save" button is invisible and when I click the edit icon on the table of 1st page, "Create" button is invisible in 2nd. App works accordingly, but could not figure out what setting enable this set-up even though I was able to make it work.
1st Page : Interactive Report Page. 2nd Page : DML Form. Built the app from blank pages.
Could any of you explain how it works?
When you click the Create button on the Interactive Report page, it takes you to the Form page in insert mode, i.e. it allows you to enter a new row into the table. Therefore, the Form page has the Create (and the Cancel) button.
On the other hand, when you click the Edit button on the Interactive Report, it takes you to the same Form page, but this time in edit mode which enables you to modify values (and save those changes with the Apply Changes / Save button), delete that row using the Delete button, or - as previously Cancel current operation.
If you look at Form page's buttons' properties, you'll see that they have Server-side Conditions set which are then used to render (or not) a certain button. For example, if the Form page number is 13 and the primary key column is set to the ID column, then these conditions look like this:
Create: P13_ID IS NULL (i.e. the primary key column value doesn't exist yet, which means that this is a brand new row)
Apply Chanages / Save: P13_ID IS NOT NULL (i.e. the primary key column value exists, which means that row you see was fetched from the database)
Delete: P13_ID IS NOT NULL (the same condition as for the Apply Chanages / Save button)
Cancel: it is always displayed.

Apex button to insert new rows

I'm using Application Express to build a page with a form that shows all the rows in Table A. Table A has to contain all the values from Table B that have a specific "Status".
I'm looking for a way to update Table A so that new rows with the correct status from Table B are added to Table A.
Is there a way to add a button to the page that inserts into Table A those rows? I have no problems with coding the query itself, but on Apex' Page Designer, when I add a button (which I called Refresh) to the page, I can't find a place to add the Insert Query.
Any tips?
there are several ways to do what you need, the simplest one would be to bind a dynamic action to the click event on the button.
On the button definition go to "Action when button clicked" region and on the action field select "Defined by dynamic action"
On execute validations choose "No"
Then, back on the page definition, create a dynamic action, on Event choose "Click", on Selection type choose "Button" this will make a field named button appear whit a list of the available buttons to choose.
In condition you can define a true/false evaluation. if so then you would be able to define actions to execute in both cases, if you leave it empty ("No condition") then all the actions defined will be executed.
Once defined click next and here you decide the action type, the one you need is "Execute PL/SQL Code", which will show a text field on which you can paste your code, and the parameters needed from the page.
finally you can specify if the action will have a repercussion on any kind of visual component on the page, this is for efficiency, but is not necessary.
That would be all, once created, when you click the button the code will be executed on the server.