Discussions
Categories
- 385.5K All Categories
- 5.1K Data
- 2.5K Big Data Appliance
- 2.5K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 584 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 45 Data Integration
- 45 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 666 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
APEX tabular form update recognition

805153
Member Posts: 9
Dear all,
I am quite new to APEX so please apologize if I am asking "stupid" questions. Unfortunately, the information I was able to find up to now was only partially helpful. Apparently I must be missing something obvious. The APEX version I use is 4.0.1.
When submitting a page that contains a tabular form, I need to find out, which record has been created or updated in order to fill in additional information automatically, e.g. logging data (created, last updated, ...). I cannot do this in a trigger, because the trigger sees only APEX_PUBLIC_USER and does not know about the "real" user who has connected to the database. If there is a better or easier way to do this, please let me know.
My problem is to find out, if a new record has been added by clicking the "add row" button and / or if an existing record has been modified, because creation and modification have to be handled differently. Existing and unmodified records in the table must not be touched. I can access the columns by using APEX_APPLICATION.G_Fxx() but how do I recognize modifications? In a thread in this forum I found information about using a MD5 checksum. So I have added a checksum field using APEX_ITEM.MD5_HIDDEN() and tried to check this information. Unfortunately, doing this, I already get a problem when I submit the page after having added an empty record by clicking on "add row" but without having supplied any information. APEX then complains about information that has been modified in the meantime instead of just ignoring the empty record. This is probably because APEX considers the record as changed because of the checksum column I have added (I have read that the SQL query to create the tabular form must not be altered).
Could anybody please show me the right way to do such a check?
Thank you very much for your help.
Best regards,
Ralf Gorholt
I am quite new to APEX so please apologize if I am asking "stupid" questions. Unfortunately, the information I was able to find up to now was only partially helpful. Apparently I must be missing something obvious. The APEX version I use is 4.0.1.
When submitting a page that contains a tabular form, I need to find out, which record has been created or updated in order to fill in additional information automatically, e.g. logging data (created, last updated, ...). I cannot do this in a trigger, because the trigger sees only APEX_PUBLIC_USER and does not know about the "real" user who has connected to the database. If there is a better or easier way to do this, please let me know.
My problem is to find out, if a new record has been added by clicking the "add row" button and / or if an existing record has been modified, because creation and modification have to be handled differently. Existing and unmodified records in the table must not be touched. I can access the columns by using APEX_APPLICATION.G_Fxx() but how do I recognize modifications? In a thread in this forum I found information about using a MD5 checksum. So I have added a checksum field using APEX_ITEM.MD5_HIDDEN() and tried to check this information. Unfortunately, doing this, I already get a problem when I submit the page after having added an empty record by clicking on "add row" but without having supplied any information. APEX then complains about information that has been modified in the meantime instead of just ignoring the empty record. This is probably because APEX considers the record as changed because of the checksum column I have added (I have read that the SQL query to create the tabular form must not be altered).
Could anybody please show me the right way to do such a check?
Thank you very much for your help.
Best regards,
Ralf Gorholt
Answers
-
I cannot do this in a trigger, because the trigger sees only APEX_PUBLIC_USER and does not know about the "real" user who has connected to the database. If there is a better or easier way to do this, please let me know.Assuming the "real" user has established their username via authentication in the APEX app, use the PL/SQL method to reference the <tt>APP_USER</tt> built-in value in the trigger:
nvl(v('APP_USER'), user)
Please refer to the documentation for more information on APEX built-in substitution strings and user identity:
http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/concept.htm#sthref151
http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/sec.htm#BABHIEIA -
Hello fac586,
thank you very much for the information. As I wrote, I must be missing something obvious...
I already knew about these substitution strings and I use them in my application in different places but I was not aware that they can be used in a trigger.
This solution solves my current problem, but I would still like to know how I can do an update detection in a tabular form myself because I might need it for other purposes.
Best regards,
Ralf Gorholt
P.S. Please excuse the multiple postings. I don't know how this has happened because I am quite sure having clicked the "Post message" button only once. Perhaps an administrator could please delete the double postings? Thank you very much. Ralf
Edited by: rgorholt on Nov 7, 2010 6:00 AM -
Hello fac586,
thank you very much for the information. As I wrote, I must be missing something obvious...
I already knew about these substitution strings and I use them in my application in different places but I was not aware that they can be used in a trigger.
This solution solves my current problem, but I would still like to know how I can do an update detection in a tabular form myself because I might need it for other purposes.
Best regards,
Ralf Gorholt -
Hello fac586,
thank you very much for the information. As I wrote, I must be missing something obvious...
I already knew about these substitution strings and I use them in my application in different places but I was not aware that they can be used in a trigger.
This solution solves my current problem, but I would still like to know how I can do an update detection in a tabular form myself because I might need it for other purposes.
Best regards,
Ralf Gorholt -
Hello fac586,
thank you very much for the information. As I wrote, I must be missing something obvious...
I already knew about these substitution strings and I use them in my application in different places but I was not aware that they can be used in a trigger.
This solution solves my current problem, but I would still like to know how I can do an update detection in a tabular form myself because I might need it for other purposes.
Best regards,
Ralf Gorholt -
Hi Ralf,
Normally there is a column that represents the ID (primary key) of the current row (hidden). When you add a new row, this has no value and is therefore NULL - until the update/insert is issued.
Ta,
Trent -
Hello Trent,
thank you for the information. I already use this method to detect newly added records but how do I detect, if an existing record has been modified or not (like APEX does it with a checksum)? Perhaps I am thinking too complicated and there is a simple solution.
Best regards,
Ralf Gorholt -
Hi Ralph,
Well, if you are wanting to check if anything has been updated before the update button is pressed, using JS, you can use the property of the field 'defaultValue' and compare it to the property 'value'
i.e. for the text input typefunction isElementChanged( myElement ) { var iselementChanged = false; var returnVal = false; switch ( myElement.type ) { case "text" : if ( myElement.value != myElement.defaultValue ) return true; break; default return false; } }
You could cycle through all elements, by:allEls = form.elements; for (i=0; i < allEls.length; i++){ if ( allEls<em>.type != undefined && allEls[i].type.length > 0 && allEls[i].disabled == false ) {<br /> if (isElementChanged(allElls[i])) {<br /> //TODO: logic here<br /> }<br /> }<br /> }<pre class="jive-pre"><code class="jive-code">Ta,<br />Trent
-
Hello Trent,
thank you very much for the information.
I will try that.
Best regards,
Ralf
This discussion has been closed.