I am using Apex 18.2. I created an interactive report which has 10 records. I try to add a logic that user can only be able to edit those records which recently created. User cannot do an edit to an old records. Means when user try to edit old records, it show as 'Display only' or not editable. Is there any way I can do that? Your help is really appreciated. Thanks
One option is to create your own link (icon, if you wish), just like another column in report's query.
As you're in SQL now, use any condition you want. Obviously, you have to be able to distinguish "old" from "new" rows. If we suppose that it is some DATE datatype column, so whatever is "yesterday" or older is considered to be "old", you'd
select case when datum < trunc(sysdate) then null
else 'Click here'
end as link,
empno,
ename
from emp
LINK column's type would be "link" (of course) and you'd make it navigate to another page in this application, pass values from here to there, etc.
Related
Very noob question, but how can I create a form in APEX that is not based on a database table?
For example, I am looking to create a "Change Password" form that consists of 3 fields:
USERNAME (display only, value populated with &APP_USER. from URL)
NEW_PSWD
CONFIRM_PSWD
None of these fields will be saved to the database, so not sure how to handle the SOURCE for the underlying form. My first thought was to just use a SQL statement like this:
SELECT '' as username,
'' as new_pswd,
'' as confirm_pswd
FROM DUAL;
Is there a better / more APEX way to handle this?
UPDATE: I understand how to set up a process to handle the logic, but more asking what should I select for the SOURCE? It "yells" at me if I select a TYPE (TABLE/VIEW, SQL QUERY, PLSQL FUNCTION BODY...) and do not put something in there.
Thanks in advance.
Don't use "Form" page type. Pick "Blank" instead.
Then
create a region on it
put any number of items (3 in your case)
create a button
create a process which will fire when you press that button
it should do "smart" things in the database - insert user into a table, change their password, whatever you plan to do
I am working with a big database and it had many generators of data basically have alot of data being inserted and updated per day. I have a trigger that updates each row every time there is an update or insert and i use the following code to input the person's name from the apex application (the user from apex)
NVL(v('APP_USER'),USER)
My problem comes when there is heavy data entry, for example 500,000 records are being generated by one person (John) and when john generated this data, each row is audited but as john generated more than one person who are users in the apex application shows up in the audit.
So scenario is that john clicks a button to generate data and in the audit fields, more than one users name show up (Mary, John, Peter)
Does anybody have any idea why this is happening?
the entire code, it is very generic
TRIGGER trg_tableA before insert or update
on tableA REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
begin
:new.insert_date:=sysdate;
:new.inserted_by:= nvl(V('APP_USER'),USER);
:new.modified_date:=sysdate;
:new.modified_by:= nvl(V('APP_USER'),USER);
end trg_tableA;
Thank you in advance
As per this link Use v('APP_USER') as default value for column in Oracle Apex There are other options than V('APP_USER'). Since Apex 5, the APP_USER is stored in the sys_context and that is a lot more performant than the V() function. It is available as SYS_CONTEXT('APEX$SESSION','APP_USER').
Please try the below and see if your issue is getting resolved.
TRIGGER trg_tableA before insert or update
on tableA REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
begin
:new.insert_date:=sysdate;
:new.inserted_by:= nvl(sys_context('APEX$SESSION','APP_USER'),user);
:new.modified_date:=sysdate;
:new.modified_by:= nvl(sys_context('APEX$SESSION','APP_USER'),user);
end trg_tableA;
Version: Oracle 18.2
I have an interactive report in my application. When I click the 'delete' icon, I want to delete information about the user I selected. Is there a way to get the value from the 'Facility Manager' column so I can use that value in a select statement to perform the delete statement.
I've tried to do it by using the ROW_ID variable (:selected_rowid) but this didn't work.
+ Interactive Report Image
+ Set Value statement
The column value is referenced by hashes, e.g. #STUDENT_ID#.
Have a look at what Jackie McIlroy wrote, "Delete a Row of a Report with a Dynamic Action" (https://jackiemcilroy.blogspot.com/2018/03/delete-row-of-report-with-dynamic-action.html) . She describes the process in details, with a lot of screenshots.
If I were you, I'd do one of the following:
use an interactive report with a form (and navigate to the form in order to delete a row)
if it has to be a tabular layout, I'd try
the old tabular form
the new interactive grid
I don't think I'd remove rows from the interactive report (but OK, that's just me, and my ideas usually aren't too smart).
I have two cascading LOVs. After changing value of my first LOV in second LOV appropriate values are populated.
First LOV:
name - P2_DEPTNO
select dname, deptno
from dept
order by 1;
Second LOV:
name - P2_EMPNO
select ename, empno
from emp
where deptno = :P2_DEPTNO;
cascading LOV parent - P2_DEPTNO
What should I add to set default value of second LOV (first row from query) after changing first LOV value?
Make sure you have Display Null Value set to No and it should use the first value in the list. (Although I am not sure what it will do with Popup LOV).
Finally, I got the correct answer on the Oracle community forum.
This is possible in only one case, because I'm more familiar with this type of issue in my project.
We need to change the second item type i,e "Empno" item type from Pop-up LOV to Select-List.
Also make null setting changes as per given below :
On DEMO works proper.
Please note that this will CAN NOT be achieved with item type as POP-UP LOV directly using simple step. To make this work using you need to work on POP-UP LOV we need so much custom changes, like DYnamic Actions , JS Code, Asynchronous calls to DB.
Source - https://community.oracle.com/thread/4048009
Author - EnigmaCoder
Apex beginner here. I have a view in my Oracle database of the form:
create or replace view vw_awkward_view as
select unique tab1.some_column1,
tab2.some_column1,
tab2.some_column2,
tab2.some_column3
from table_1 tab1,
table_2 tab2
WHERE ....
I need the 'unique' clause on 'tab1.some_column1' because it has many entries in its underlying table. I also need to include 'tab1.some_column1' in my view because the rest of the data doesn't make much sense without it.
In Apex, I want to create a report on this view with a form for editing it (update only). I do NOT need to edit tab1.some_column1. Only the other columns in the view need to be editable. I can normally achieve this using an 'instead-of' trigger, but this doesn't look possible when the view contains a 'distinct', 'unique' or 'group by' clause.
If I try to update a row on this view I get the following error:
ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
How can I avoid this error? I want my 'instead-of' trigger to kick in and perform the update and I don't need to edit the column which has the 'unique' clause, so I think it should be possible to do this.
I think that you should be able to remove the "unique".
if tab2.some_column1, tab2.some_column2, tab2.some_column3 are not unique, then how do you want to update them ?
if they are unique then the whole result: tab1.some_column1, tab2.some_column1, tab2.some_column2, tab2.some_column3 is unique.
When you state in a sql query "unique" or "distinct" it's for all columns not only 'tab1.some_column1'
Hope i'm in the correct direction of your question here ;)
Your query could be achieved by doing something like:
select a.some_column1, tab2.some_column1, tab2.some_column2, tab2.some_column3
from table_2 tab2
join (select distinct some_column1 from table_1) a
on tab2.column_in_tab1 = a.some_column1
The reason you get the ORA-02014 error is because of the automatically generated ApplyMRU process. This process will attempt to lock a (the) changed row(s):
begin
for r in (select ...
from vw_awkward_view
where <your first defined PK column>= 'value for PK1'
for update nowait)
loop
null;
end loop;
end;
That's a bummer, and means you won't be able to use the generated process. You'll have to write your own process which does the updating.
For this, you'll have to use the F## arrays in apex_application.
If this sounds totally unfamiliar, take a look at:
Custom submit process, and on using the apex_application arrays.
Also, here is a how-to for apex from 2004 from Oracle itself. It still uses lots of htmldb references, but the gist of it is there.
(it might be a good idea to use the apex_item interface to build up your form, and have control over what is generated and what array it takes.)
What it comes down to is: loop over the array containing your items and do an UPDATE on your view with the submitted values.
Of course, you don't have locking this way, nor a way to prevent unnecessary updates.
Locking you can do yourself, with for example using the select for update method. You'd have to lock the correct rows in the table(s) you want to alter, before you update them. If the locking fails, then your process should fail.
As for the 'lost update' story: here you'd need to check the MD5-checksums. A checksum is generated from the editable columns in your form and put in the html-code. On submit, this checksum is then compared to a newly generated checksum from those same columns, but with values from the database at that time of submit. If the checksums differ, it means the record has changed between the page load and the page submit. Your process should fail because the record has been altered, and you don't want to have those overwritten. (if you go the apex_item way, then don't forget to include an MD5_CHECKSUM call (or MD5_HIDDEN).
Important note though: checksums generated by either using apex_item or simply the standard form functionality build up a string to be hashed. As you can see in apex_item.md5_hidden, checksums are generated using DBMS_OBFUSCATION_TOOLKIT.MD5.
You can get the checksum of the values in the DB in 2 ways: wwv_flow_item.md5 or using dbms_obfuscation.
However, what the documentation fails to mention is this: OTN Apex discussion on MD5 checksums. Pipes are added in the generated checksums! Don't forget this, or it'll blow up in your face and you'll be left wondering for days what the hell is wrong with it.
Example:
select utl_raw.cast_to_raw(dbms_obfuscation_toolkit.md5(input_string=>
"COLUMN1" ||'|'||
"COLUMN2" ||'|'||
"COLUMN5" ||'|'||
"COLUMN7" ||'|'||
"COLUMN10" ||'|'||
"COLUMN12" ||'|'||
"COLUMN14" ||
'|||||||||||||||||||||||||||||||||||||||||||'
)) md5
from some_table
To get the checksum of a row of the some_table table, where columns 1,2,5,7,10,12,14 are editable!
In the end, this is how it should be structured:
loop over array
generate a checksum for the current value of the editable columns
from the database
compare this checksum with the submitted checksum
(apex_application.g_fcs if generated) if the checksums match,
proceed with update. If not, fail process here.
lock the correct records for updating. Specify nowait, and it
locking fails, fail the process
update your view with the submitted values. Your instead-of trigger
will fire. Be sure you use correct values for your update statement so that only this one record will be updated
Don't commit inbetween. It's either all or nothing.
I almost feel like i went overboard, and it might feel like it is all a bit much, but when you know the pitfalls it's actually not so hard to pull this custom process off! It was very knowledgable for me to play with it :p
The answer by Tom is a correct way of dealing with ths issue but I think overkill for your requirements if I understand correctly.
The easiest way may be to create a form on the table you want to edit. Then have the report edit link take the user to this form which will only update the needed columns from the one table. If you need the value of the column from the other table displayed it is simple when you create the link to pass this value to the form which can contain a display only item to show this.