Forum Stats

  • 3,780,660 Users
  • 2,254,421 Discussions


"current/displayed" page form field value (before submit)

RTitsworth-Oracle Member Posts: 7 Employee
edited Oct 15, 2021 12:16AM in APEX Discussions

I am using a SetValue dynamic action to set the value for a form field (:Field#1), based on the "displayed" value of another field (:Field#2) on the same page/form (before submit). This action is being triggered based on the LostFocus event of Field#2.

Currently, the LostFocus event and SetValue actions trigger as desired, but the value from Field#2 being used, is the original (db state) value, not the current/displayed (pending submit) value shown on the screen.

Is there a way (using PL/SQL or other) to reference the "current/displayed" value in a form field (before the page is submitted).

Ref: PL/SQL SetValue expression for Field#1, triggerd from Field#2 lost focus dynamic action...

CASE WHEN ( :Field#2 = 'something currently displayed' ) THEN 'this is the new value for Field#1' END

Thanks ;-)


  • AlexH-Oracle
    AlexH-Oracle Member Posts: 14 Employee

    Hey there - I understand you're using "Set Type = PLSQL Expression" to set that value.

    PLSQL can only access what is already in the session state, or already submitted. If you're changing something on the page, surely enough when the PLSQL executes as a result of the dynamic action, it will only have in it's context the "old" value and not the "new". The way to make the "new" value available is to submit it - which can be done from the dynamic action, without having ot submit the entire page.

    What you need to to is this: fill in the "Items to Submit" field (right beneath the plsql expression) with the ID of Field#2.

    Let me know if it worked!

  • RTitsworth-Oracle
    RTitsworth-Oracle Member Posts: 7 Employee
    edited Oct 15, 2021 2:41AM

    Thanks for the reply. I learned something new. Works like a charm !!!

    p.s. FWIW, as I strated to think more about the situation, I was afarid it would never work (easily) as I intended... My form is part of a create new record process (i.e.DB insert). So, it's not that the underlying (old/stale) field#2 value is from the DB at initial form load, but rather it is null. From an execution time/sequence standpoint, there is no underlying db record yet (until the form gets submitted, validation checks., Key field sequence trigger, etc). So, how does the "item to submit" process actualy work??? Hmmm don't know, but it does. Magic I guess. and/or I need to learn more about session states (some weekend reading). THANKS AGAIN ;-))

  • AlexH-Oracle
    AlexH-Oracle Member Posts: 14 Employee

    Ok, this is going to be a longer post - sounds like you need a bit of background here, so let's go into the details of how this works for a bit

    There is absolutely no need to save to the database beforehand.

    Whenever you login to an apex app, a session is created. This session essentially holds the values in the various fields on the page. Like a text field, for example. They're variables, really. When you submit a page, teh values in the various fields in the form get saved in the session.

    The session is "in memory", and it resides on the server. For it to actually end up in the database, there needs to be some sql or plsql to actually take it from the session and write to a table.

    There is a third layer to this, and that is your browser. So it's database -> session -> browser.

    Whenever you make a change to a field on your page but did not submit yet, then that value only exists in your browser state.

    After you click submit, the value gets saved in the session stage.

    After a SQL insert statement (for example) it goes in your database.

    One other thing to keep in mind is that plsql can only access the session state. This is important going forward.

    Now let's look at your particular case:

    When the page loads, the value displayed in the field is pulled from the session state. Even if that is null (such as when creating something), it is still coming from the session state. So in your case, when the page loads FIELD2 has null as the value in the session state. And it has a null value in the browser state.

    You now change the value on FIELD2 to "apexisawesome". At this point two things happen:

    • The value in your browser state is "apexisawesome";
    • The value in your session state (which is on the server) is still null because you did not submit the page yet;

    Now the dynamic action triggers and you expect it to execute some plsql. Specifically, you want it to take the value from Field2 and assign it to Field1. Remember what we said earlier: plsql can only pull form the session state, since it executes on the server. But in your session state (on the server) Field2 = null. The new value only exists in your browser.

    So what you can do, is to make sure that the new value "apexisawesome" first is transfered from your browser state on your local machine to the session state on the server (where that plsql will execute).

    The way to do that is this:

    • Set up a Dynamic Action on Field2 - set it to either Lose Focus or On Change;
    • For the True Condition put in a "Set Value"
    • For the Set Type put in "PLSQL Expression"
    • For now, just put in :P100_FIELD2 (considering that's the name of your field);
    • For the "Items to Submit" right beneath put in P100_FIELD2 (without the colon in front);

    This should work just fine. Once you get it working, you can change the plsql expression to whatever you need. If it still doesn't work, please bring in some code and screenshots.

  • RTitsworth-Oracle
    RTitsworth-Oracle Member Posts: 7 Employee

    It works/worked fine just as you originally posted. But, I was not 100% clear on why/how.

    Your long msg above is very much appreciated - clears up lots of things.


  • AlexH-Oracle
    AlexH-Oracle Member Posts: 14 Employee

    hey - would appreciate it if you'd mark the post as answered :) it will show the thread as resolved