How to get the values in items without refreshing the page in apex - oracle-apex

I have an item to enter email id, and two more items to get the values of first/last name and department of that user which we have given without refresh the page or without enter.
Item 1: ex : a...z#gmail.com (text field)
Item 2 : ex Mechanical (display only)
Item 3 : ex Abinnaya Moorthy (display only)
This should happen when we have given the email id and as soon as the cursor is out from email id the two item values should display.
I have used dynamic action but not getting exact output, please let me know.

On Item 1 make a following dynamic action:
Event: Change (I would recommend 'change', although based on your question, you might also be interested in 'Mouse Leave', although it would trigger DA even when no change in item value occurred, for example when someone just clicked on it and clicked away)
Selection Type: Item
Item: your Item 1
First true action: Execute PL/SQL Code
inserting values into your items Item 2 and Item 3, while using your Item 1 as a condition in WHERE clause
Page Items to Submit: your Item 1
Page Items to Return: your items Item 2 and Item 3
Second true action: Refresh
Selection Type: Item(s)
Item(s): your items Item1 and Item2

Let's say I have 1 field like an email field above. Then I have 50 display only fields that values are coming from (Source) SQL queries that depends on email field. How to refresh this fields without refreshing page, but also without Setting its value manually? I would only like to trigger them to perform their Source SQL query and refresh values on the page.
Setting their values by SetValue action will result in having same queries in Dynamic Action and in Source SQL Query for each field. Also for 50 fields DA would have hundreds of SQL lines and would become not maintainable.

assuming you are working on page 9, and the email field is :P9_EMAIL_ITEM, and the name fields are :P9_FNAME_ITEM and :P9_LNAME_ITEM
The email field is a text field (it doesn't matter what the source is)
The name fields should be display only, and in properties the setting "Based On" should be "Page Item Value", set the source property to type Null.
On the email text field, create a new dynamic action, set the When properties to: Event -> Change, Selection Type -> Item(s), Item(s) -> P9_EMAIL_ITEM
Under the dynamic actions you'll have a "New" event, with a "True" folder, and inside it a new action (probably "Show"). Change its action to "Set Value".
change the setting property so that "Set Type" will be "SQL statement", and write a statement with the following structure:
select FNAME_COLUMN, LNAME_COLUMN
from RELEVANT_TABLE
where EMAIL_COLUMN = :P9_EMAIL_ITEM
Under "Items to submit" select the P9_EMAIL_ITEM.
in the Affected Elements properties set Selection type -> Item(s) and Item(s) -> P9_FNAME_ITEM, P9_LNAME_ITEM
In "Execution Options" select NO for Fire on Initialization
what we did on step 5 is "refreshing" the relevant items, without refreshing the page

I just tested it out and here's what works very well:
On Item 1, create a DA on 'Loose Focus'
Create two true actions for 'Set Value', for both Item 2 and Item 3.
Select Settings > Set Type as SQL Statement.
Write query to fetch item 2 and item 3, base on item 1 (I suggest comparing lower cases of both to make it case in-sensitive.)
Items to Submit -> Item 1
And viola, it's done!

Related

Get Select list Item value in IG report column for DML operation

I have a Select list filter on the top of the page. I want its return value to get into any column which I create in IG report automatic DML process.
Suppose, Select list has a value "Step", when I add a row in IG report, that value should be saved into DB for one column which is hidden on UI.
I tried but sometimes it stores the value which I selected in Select list item as my last selection not the current one. Do I need to create Application item for this? Please help. TIA
In this case there is a table ig_tickes with a status column. On the page there is a page item P131_STATUS (select list) with values "OPEN" and "CLOSED". There is an interactive grid on table ig_tickets with column STATUS hidden. Functionality is that user selects a value from the select list and then clicks "Add Row".
Give the interactive grid a static id of "tickets"
Create a dynamic action on change of P131_STATUS with a true action of type "execute javascript code" and code:
var model = apex.region("tickets").call("getViews").grid.model;
model.getOption("fields").STATUS.defaultValue = apex.item( "P131_STATUS" ).getValue();
That's all there is to it.

Oracle Apex Dynamic action not working for form items

I have a form with items P1_APP and P1_USER.
P.S. P1_USER is select list.
Display John
Return 1
Display Andy
Return 2
I need to disable when user selects John.
When P1_USER = 'John', P1_APP should get disabled which is a multi select list.
I created dynamic action on P1_APP, True Action= Disable,Affected element P1_APP
Client condition : Item =Value
Item= P1_USER
Value= John
However this is not working.
I have used similar logic to disable interactive grid items and was able to do so. Why is this not working for form?
EDIT: In Value now i am putting 1 which is return value for John.
However when i select John. It disables P1_App upon clicking. But remains disabled even when i choose Andy.
This works for me using the following configuration.
Create form and report on EMP - everyone has access to that sample data, it is a good idea to post questions based on that.
In the form P3_DEPTNO is a select list with source
SELECT d.dname, d.deptno FROM dept d
Add a page item to my form P3_APP. This is a select list with "Allow multi selection" enabled. Select list has 2 static values.
Create a dynamic action on change of P3_DEPTNO.
Client side condition: Item = Value
Item: P3_DEPTNO
Value: 30 (note that this is the return value for SALES, not display value)
add true action of "Disable", affected item P3_APP
Click true action and select "Create Opposite Action". Save.
When I run this it work. Selecting SALES in the select list disables the item P3_APP and selecting something else enables it.

How to pass data between fields in Oracle APEX 5.1?

This is a VERY basic question. Sorry for not providing any code I have NO IDEA how to even start tackling the problem
I have lets say two fields... One is a date selector field and the other a regular text field. What I want is when I select a date (or type a date), the value comes in the second field... Just that...
I'm on APEX 5.1.4
Since you have stated that the second item is a text field, you could do this with the help of a dynamic action that sets the value of the second item when there is a change in the value of the first item ( date field).
The following would be the steps, if you are using component view:
Create Dynamic Action
When
Event : Change
Selection : Item(s)
Item : First Page Item
Condition : is not null
True Action
Action : Set Value
Fire on Page Load: No
Set Type: You can choose how you want to set the value of the second item on the page.
If you have the flexibility to change the second item to be a select list and you have a list of values that goes with a date, you could do this much simpler, with a Cascading LOV
On Second Item's - Under List of Values section
Cascading LOV Parent Item(s) : First Item
Page Items to Submit: First Item
List of Values definition: Here you can define the query.
Hope this helps.
There are a few different ways to do this, probably the easiest way is as follows.
Assume your two items are P1_ITEM1 and P1_ITEM2.
Create a dynamic action which fires on change of item P1_ITEM1.
The true action of this should be action:set value, set type:PL/SQL Expression, item::P1_ITEM2, items to submit P1_ITEM1.

Oracle Apex - Select list populates text field

I'm using Oracle Apex 4.2. I have a select list and a text field. I'm trying to create a dynamic action that should be simple enough but I'm not sure how to do it. Basically depending on what value the user selects from the list of values in the select list, the text field should then be populated. So for example:
Let's say the select list gives the user the choice to select 'Animal', 'Car', 'Person'. If the user selects 'Animal' then the text field should immediately have the value 'cat'. If the user selects 'Car' then the text field should immediately have the value 'toyota'. If the user selects 'Person# then the text field should immediately have the value 'jim' etc.
How would I make this dynamic action?
Thanks,
Stephen.
Create a New Dynamic Action with the following properties
Main Properties
Event: Change
Selection Type: Item
Item(s): [Select List]
Condition: No Condition
True Action
Action: Execute PL/SQL code
Fire When event Result is: True
PL/SQL Code:
Option 1 - use a lookup table
select LOOKUP_VALUE
into :P1_TEXT
from LOOKUP_TABLE
where original_value = :P1_SELECT_LIST;
Option 2 - Use hardcoded values
CASE upper(:P1_SELECT_LIST)
WHEN 'ANIMAL' THEN :P1_TEXT := 'cat';
WHEN 'CAR' THEN :P1_TEXT := 'toyota';
WHEN 'PERSON' THEN :P1_TEXT := 'jim';
ELSE :P1_TEXT := null;
END CASE;
Page Items to Submit: [P1_SELECT_LIST]
Page Items to Return [P1_TEXT]

Trigger a process (SQL update) when leaving an APEX page

This is a very odd question but i wondered whether it was possible to trigger a process that runs an SQL UPDATE when the user leaves this specific page, either by clicking on the breadcrumb, tabs or back button?
I did setup the process to run on the 'Back' button; however i ran into the problem of: What if s/he clicks on the breadcrumb or a tab instead.
I have searched the net and posting this question was a last resort. I wondered if anyone can point me in the correct direction?
UPDATED POST
Page 1:
Includes a text field and a button. The user enters the category into the text field and clicks on the button to proceed to the next page. The button passes the value in the text field to a text field on Page 2.
Page 2:
Two regions on the page. One region holds information about the category - Category name from the previous page, category description, and the category revision number (which is what i'm trying to get working). The second region is a report that pulls the item name and number that are listed under the category in the category text field. A 'View' link is used on the report to load the edit page for the specific item selected. The 'View' link passes the 'category name' (from the category text field) and the 'item number' from the report to page 3.
Page 3
Two regions are used, first region: Lists the Item number which came from page 2 and name of the item (which i use a simple query to retrieve). In the second region: A report is used with two columns: a list of item properties in column 1, and a text field next to each item property in column 2 to hold the value that can be updated. The 'Apply Changes' button has some PlSql behind which looks for changes and updates where required. It updates the relevant fields that have changed, and it then takes the user back to Page 2 (Page showing user the items listed for the category intitally entered).
I cant increase the category revision on the 'apply changes' button on page 3 because the user may complete edits for items under the same category. So i dont know where i can increase the category revision by 1 per vist to a category. P.s I already increment the revision number for each item by 1 if the info has been changed using the 'apply changes' button on page 3.
One way of doing this is by updating the session state of the page items (without submitting the page as normal) via ajax and by calling an Application Process which updates the table, when called by a javascript onbeforeunload.
Create an Application Process to fire On Demand, named UpdatePageXOnExit or something. In the PL/SQL block of that Application Process, use SQL update commands with the item state of each item on the page that you wish to update; something like the following:
BEGIN
UPDATE table_name SET col1 = :PX_ITEM_1, col2 = :PX_ITEM_2, col3 = :PX_ITEM3, col4 = :PX_ITEM_4, col5 = PX_ITEM_5
WHERE (condition... I would suggest ROWIDs to simplify changes to the
fields of the PK; otherwise you will have to create additional
page items for each field of the PK, then set those items to
the values of the PK when the page loads using a before
header page process, and then use those values in this where
clause like this: where col1 = :PX_ORIGINAL_PK_FIELD_1 AND col2 =
:PX_ORIGINAL_PK_FIELD_2 );
END ;
Go to the page settings for that particular page, and in the JavaScript: Execute On Page Load section, write something like the following:
window.onbeforeunload = updateOnExit;
And in the JavaScript Function and Global Variables Declaration, write something like the following:
function updateOnExit() {
var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=UpdatePageXOnExit',&APP_PAGE_ID.);
get.add('PX_ITEM_1',$x('PX_ITEM_1').value)
get.add('PX_ITEM_2',$x('PX_ITEM_2').value)
get.add('PX_ITEM_3',$x('PX_ITEM_3').value)
get.add('PX_ITEM_4',$x('PX_ITEM_4').value)
get.add('PX_ITEM_5',$x('PX_ITEM_5').value)
gReturn = get.get();
get = null;
// Comment out the following line or not, as per the note in the following paragraph
return 'Are you sure you would like to leave the page?';
}
This last piece is the AJAX that updates the session states of the page items on the page that have been changed on the user's end but that haven't been uploaded to the servers end which normally occurs during page submission. Note: If you comment out the return statement, than there will be no warning box that will allow the user to stay on the page. If that is what you prefer, go for it. If you chose to use the warning box, the ajax will execute the page process even if the user chooses to stay on the page.