Oracle Apex: Setting Page Items using SQL - Not adding to Session - oracle-apex

I don't see the values in Session when using the Debug, but the page items are rendering:
I am setting the Source using a SQL Expression:
And I know the query is working, as the page item is rendering out for P2_KPI_NAME on the page.
Why are they not being added to Session once calculated?

The fact that you see it doesn't mean it is in session state.
For testing purposes, create a button on that page which will perform SUBMIT. Push it, and then check Session tab in Debug output.

You could use a dynamic action on change of :P2_KPI_ID in which you set your second item using PL/SQL (remember to add P2_KPI_ID to Item to Submit aswell as your second item as a Item to Return).
"Always replace value in Session State" sets the items value when its getting rendered.The item itself is not refreshed when your :P2_KPI_ID is set and therefor its value is not set automatically.

You're seeing the result of a performance optimization used during page rendering. Most of the time we think of session state, we think of persisted session state, i.e. the state in the session table.
However, in-memory session state is often used by APEX when rendering a page to avoid the overhead of running DML against the session table when it usually doesn't need to be there anyway (the next submit will overwrite it).
See this old, but still relevant, post to learn more:
http://c2anton.blogspot.com/2008/12/oracle-application-express-apex-three.html

Related

Pass values between pages Oracle APEX

There is a problem transferring values between pages in the application. I have 2 pages on the first page there is a variable P9_ITEMID (when you run page 9, in this variable SQL Statement query writes the data). There is a second page 181. I want to move data from variable P9_ITEMID to variable P181_ITEM. To do this, I use the 'redirect to page in this application' option. But it doesn't work. Although I see in the variable P9_ITEMID there is data. But when you go to page 181 but P181_ITEM is empty. I would be grateful for help))
P9_ITEMID is a virtual variable that is not assigned to any column in the table. This mmin simply displays data. When I start the page, I see the data that was written to it due to the dynamic action
also i tried to write the value in P9 ITEMID this way
My code:
declare
v_empname items.id%type;
begin
select id into v_empname
from items where id = :P9_ITEMID;
apex_util.set_session_state('P9_ITEM_ID', v_empname);
exception
when others then
apex_util.set_session_state('P9_ITEM_ID', null);
end;
I'm assuming that you have created a button with action: 'redirect to page in this application' and you want the session value of a page item to be passed to the target page.
When an url is constructed using link builder, the link is built at page rendering time. It does not pick up any changes in session. Even when you set the session state in a dynamic action, it will not pick it up because the url is already rendered.
To pick up any changes on that page, it is necessary that the page item value is set in session state and this is done by the "page processing".So if you use "Submit Page" on the button and create a branch to redirect to the page it will behave the way you want.

"general" variable in oracle apex

I'm developing an application in Oracle Application Express (APEX).
First page contains list of projects as a tabular report.
Clicking any of the rows forwards to the next page, where records can be edited. I've implemented it with following settings:
Link column: link to custom target
Target: Page in this application
Until this is fine.
My problem is how to pass actual report to the next page?
My table, which is the basis of the report has primary key (ID), and also owner & title combination is unique. Currently ID column is not included in the report.
Also the second page doesn't currently contain field showing ID, as this information isn't important to the users.
I know I could set ID column in report, and create a read only (even hidden) text box in the next page, however I'm looking for a more elegant solution. What is the standard way to solve this?
I wonder if you are asking: "How do I pass a value from page 1 to page 2 so page 2 can use the value to do a query and present the results. If so, here is how it's done.
On page P1, the report, for example, select the attributes for the report region under the region in the Rendering pane on the left of the page designed.
Under Attribute Properties on the right side, look for Link Column and set it to "Link to custom target". Then click Target.
Select the page and then in the Set Items section, on the left, under name, select the PK ID field to receive the passed value ex: P2_ID. On the right under Value select the field to pass the value, ex: #P1_ID# and click ok.
Now, when the link on page 1 report is clicked, the P1_ID is saved into Session state by Apex and passed to P2 which then performs a FETCH using the passed value.
You can read more about Session State here. Also, be aware there are security settings which affect what params can and can't be passed in the URL.
Clicking "Session" in the developer toolbar will enable you to see the session variables being passed.
If you mean "How do I store values in the app that can be accessed anywhere in the app - like a global variable" Then look at Application Items.
As always, please include version numbers in these posts.
When you create a target page let's say Page 3
And you create some items, let's say P3_ITEM_1,P3_ITEM_2, etc
You can assign values to each of them through the url in the original page
The complete APEX URL Syntax looks like this:
http://apex.oracle.com/pls/apex/f?p=AppId:PageId:Session:Request:Debug:ClearCache:Params:ParamValues:PrinterFriendly
Let’s take a closer look:
http:// – the protocol, can be http or https
apex.oracle.com – your domain/host/server, whatever you want to call it. Can also be localhost.
/pls – indicates that you are using Oracle HTTP Server with mod_plsql. If you are using APEX Listener or Embedded PL/SQL Gateway this part is obsolete/missing.
/apex – the entry from your dads.conf file (this a file on your application-server or EPG where the target database is configured) – in case of EPG its just one entry pointing to localhost, in case of an OAS you can have multiple entries, each pointing to an other database
/f?p= – procedure “f” is called and parameter “p” is set to the complete rest of the string. Remember: APEX uses mod_plsql. “f” is a public procedure, this is the main entrypoint for APEX. Or you could say: “f” is APEX.
AppId – the number or the Alias of the Application
:PageId – the number or the Alias of the Page
:Session – unique Session ID, can be 0 for Public Pages or empty (then APEX creates a new Session)
:Request – a Request Keyword. This is basically free text, just a string you can specify to react in a process or region condition on. e.g. you could pass the keyword “CREATE” and have a condition on the delete button of your page saying “dont’t display this button if request is CREATE”.
In other words: use the REQUEST to control the behaviour of your page.
When pressing a button, the button sets the REQUEST to the button-value (e.g. SAVE), so that you can control the processes in the page processing (Submit) phase.
:Debug – set to YES (uppercase!) switches on the Debug-Mode which renders debug-messages and timestamps in your Browser window. This helps to detect wrong behaviour of your page or performance issues and everything else. Every other value then YES turns the Debug-Mode off
:ClearCache – you can put a page id or a list of page ids here (comma-separated) to clear the cache for these pages (set session state to null, …). But there is more: RP resets the pagination of reports on the page(s), a collection name deletes the collection, APP clears all pages and application-items, SESSION does the same as APP but for all applications the session-id has been used in.
:Parameters – comma seperated list of page-item names. Good practice is to set only those page-items which are on the page you are going to. Accepts page-items as well as application-items.
:ParamValues – comma separated list of values. Each value is assigned to the corresponding Parameter provided in ParamNameList (first value assigned to first parameter, second value assigned to second parameter, and so on…).
The trick here is not having values which contain either a comma “,” or a colon “:”. Both would lead to side-effects and errors, as APEX gets confused when parsing the URL. Using a comma works, if enclosed by slashes: e.g. \123,89.
:PrinterFriendly – set to YES (uppercase!) switches the page into PrinterFriendly-Mode, uses the Printerfriendly template to render the Page. You can also hide regions or other elements in PrinterFriendly-Mode using the PRINTER_FRIENDLY variable in a condition.
In your case you'd use Params:ParamValues like this:
P3_ITEM_1,P3_ITEM_2:someValue_1,someValue_2
Documentation

How to set the default result set of Oracle APEX form to be empty?

When accessing an Oracle APEX form, the form automatically returns a set of results.
Is there a way to make the default/initial result set of a form to be empty?
I want the users to see nothing when they visit the page and I want the users to use the search bar to search for the records.
You probably want the clear cache parameter in the URL to be the page number, clearing out session state for all your page items.
http://docs.oracle.com/database/apex-5.1/HTMDB/understanding-url-syntax.htm#GUID-F249FDCA-972B-4DFB-A51B-DD127AAB9C35
Adjust this in the navigation link to the page.
Alternatively, you can define a calculation, or set the source of the relevant items to always be null.

Oracle Apex Set values before moving to another page, Items are all null

I am trying to do the following:
Anonymous user with a unique key enters a code and clicks 'Start Survey'
The button needs to call a plsql process to populate some hidden page items.
Once the values are set branch to the survey page which will use the hidden items for filtering results.
The Problem
No matter what I have tried so far the items set by the process are null when I get to the next page. I assume this is because it did not submit. The way I have it at the moment is:
Button navigates to the next page
New process set to when the button is pressed sets the values of the page items.
By the time it gets to the next page they are blank again.
I could set the button to submit and do the branch in the processing but I think the submit would happen before the values are set. I find it confusing what order these things happen in.
Can I please get help with making this work, and is there a good article on understanding this area better?
here is the code from the process that puts the values in:
Begin
select id into :P1_pat_id
from lic_paticipent
where unique_id = :P1_unique_code;
select sur_id into :P1_sur_id
from lic_paticipent
where unique_id = :P1_unique_code;
select id into :P1_first_res_id
from lic_result r
where r.pat_id = :P1_pat_id
and r.sur_id = :P1_sur_id
and r.qop_id is null
and rownum = 1;
End;
Thanks in advance for your help.
OK I solved it and it is my playing around with another issue that cased it.
I had set the hidden fields to "Always replacing" instead of "Only when null" so the plsql process updated the session but not the item so when I did a submit the null item replaced what the plsql process had set. I had expected that when the session was updated it would update the item also.
I worked it out by making the hidden field visible and could see it was blank but had a value when I checked the session state.
Hidden page items in your current page cant be used in other pages unless your current page is a global page. You have to pass the value to another page item in the other page.
Try this:
Go to the other page and Create hidden items to catch the value to be passed from the first page.
Go back to the first page and retain your process and create a branch process. then set it to redirect to another page. then you'll see Set items below. Put your hidden items in the other page in the left side then your hidden items in your current page in the right side in this format &P1_NEW.(with the period)
It should look like this
Set Items
P11_PAT_ID--------------------------&P1_PAT_ID.
P11_SUR_ID--------------------------&P1_SUR_ID.
etc.

Copy Records in Oracle Apex

I need to copy selected row values and store as a new record.
I am using Oracle Apex 4.2 and Tabular Form.
I need to use checkbox to select the rows and button copy. When i select multiple rows followed by click copy button to copy all the selected row values as new rows and save.
Can anyone Help
Copying Records Through an APEX Tabular Form Input
The idea of cloning existing records from a single table through an Oracle APEX Tabular Form works without much interference with the default design that you can set up through the APEX wizard for page region content.
Build a table with an independent primary key.
Suggested to include two auxiliary columns: COPY_REQUEST and COPIED_FROM for running copy operations. Specific form elements will map to these columns on the tabular form that will be set up.
Build an Oracle stored procedure that can read which records need to be copied. This procedure will be invoked each time the SUBMIT button is pressed.
(optional) Consider including a suppression of step (3) in the event that there is nothing to process (i.e., no records marked for copying).
The Working Table for Receiving Input: COPY_ME
TIP: You will have an easier time if you use the standard TABLE creation wizard. Designate CUSTOMER_ID as the PRIMARY_KEY and have APEX create its standard auto-incrementing functionality on top. (sequence plus trigger set up.)
Here's the sample data I used... though it doesn't matter. You can put in your own values and be able to verify what happened easily.
The Heavy Lifting: The Stored Procedure for Cloning Records in COPY_ME
This procedure works with 1 or more records at a time with a special identifier in the COPY_REQUEST table. After the task is done, the procedure cleans up and resets the request value again.
create or replace procedure proc_copy_me_request is
c_request_code CONSTANT char(1):= 'Y';
cursor copy_cursor is
SELECT cme.CUSTOMER_ID, cme.CUSTOMER_NAME, cme.CITY, cme.COUNTRY,
cme.COPY_REQUEST
FROM copy_me cme
WHERE cme.COPY_REQUEST = c_request_code
FOR UPDATE OF cme.COPY_REQUEST;
BEGIN
FOR i in copy_cursor LOOP
INSERT INTO copy_me (customer_name, city, country, copied_from)
VALUES (i.customer_name, i.city, i.country, i.customer_id);
UPDATE copy_me
SET copy_request = null
WHERE CURRENT OF copy_cursor;
END LOOP;
COMMIT;
END proc_copy_me_request;
There is also a column that can be hidden. It tracks where the record was originally copied from.
Note that the cursor is using the FOR UPDATE OF and WHERE CURRENT OF notation. This is important because the procedure is changing the records that are referenced by it.
APEX Page Setup Instructions
Set up a standard FORM type page and choose the TABULAR FORM style. Follow the set up instructions, taking care to map the correct primary key, and also to the PK sequence object created with the table in the previous steps above.
This is what your page set up will look like after these steps are completed:
EDIT The COPY_REQUEST Form Value:
Under the column attributes section, change the Display As option to "simple checkbox"
Under the list of values section, put a single value under the LOV Definition: Y (case sensitive in either way... just be consistent)
EDIT The COPIED_FROM Form Value:
Under the column attributes section, change the Display As option to "Display as Text(Saves State)". This is just to prevent users from stepping on this read-only field. You could also suppress it if it isn't important to know.
CREATE a New Process: Execute Copy Procedure
This is the bottom of the same configuration page, there are very few things to change or add:
Demonstration: Screenshot of COPY_ME Tabular Form Page in Action
The first screenshot below is before the page is tidied up and the checkbox control is put into place.
Plug in some test data and give it at try. The Page Process created in the step above conditionally invokes the stored procedure that processes all copy requests made at the same time when the SUBMIT form button is selected.
COMMENTS: If you spend enough time tinkering around with the built-in wizards in Oracle APEX, there are opportunities to learn new design patterns and process flows compatible within the tool. Adapting your approach can reduce the amount of additional work and frustration.