Forum Stats

  • 3,874,814 Users
  • 2,266,777 Discussions
  • 7,911,968 Comments

Discussions

Q:Determine if a item value has changed

20378
20378 Member Posts: 577
edited Mar 19, 2013 9:24PM in APEX Discussions
Hello,
I am sure I am missing something basic but I just can't figure out how to do accomplish this.

I have a form with a radio button (Yes or No) which I need to determine in a Page Process if the user has changed the value to Yes or not. The result of this will decide if I am going to send an email or not.

I am running APEX 4.2.1.

Anyone?

Thanks
Andy

Best Answer

  • Roel Hartman
    Roel Hartman Member Posts: 2,711 Gold Trophy
    Answer ✓
    1. You can compare the current value (:Pxx_RADIO) with the value in the database
    2. You can store the value on Page Load in another (duplicate) item and compare both of them
    (3. You can do it in a database trigger - but some people advocate against that ;-) )
«1

Answers

  • Roel Hartman
    Roel Hartman Member Posts: 2,711 Gold Trophy
    Answer ✓
    1. You can compare the current value (:Pxx_RADIO) with the value in the database
    2. You can store the value on Page Load in another (duplicate) item and compare both of them
    (3. You can do it in a database trigger - but some people advocate against that ;-) )
  • Howard (... in Training)
    Howard (... in Training) Member Posts: 905
    edited Mar 19, 2013 2:14PM
    Can they change Yes/No only once per page submission? (You don't want to take action if they just keep toggling the control. Right?) If you want to capture each change you would have a Dynamic Action for that. But I'm sure you don't want that.

    For once per page decisions, I typically save the initial value in a before header process:
    :Pxx_RADIO_LAST := :Pxx_RADIO;
    Then as Roel said, when you submit the page you can have an action to check if :Pxx_RADIO = :Pxx_RADIO_LAST and execute whatever process is needed.
    Howard (... in Training)
  • 20378
    20378 Member Posts: 577
    Need a little bit more information....
  • 20378
    20378 Member Posts: 577
    You are correct, once per page descision is what I am trying to accomplish.

    So, I create a PL/SQL process after the Fetch Row process and assign as you suggested
    :Pxx_RADIO_LAST := :Pxx_RADIO;
    But I am not sure how to create the item :Pxx_RADIO_LAST. I would assume it should be hidden but what should the source value be set to?

    Thanks
    Andy
  • Howard (... in Training)
    Howard (... in Training) Member Posts: 905
    edited Mar 19, 2013 2:48PM
    You could always create an Application Item but I prefer to keep this one on the same page.

    Yes, a Hidden Item. Hmm. I need to remind myself whether Hidden Items are saved in the Session State. It might not matter if you are only doing a local on-page test / computation. But try it out and I'll see if I can check on it.

    Regards,
    Howard
  • 20378
    20378 Member Posts: 577
    edited Mar 19, 2013 2:58PM
    Thanks,
    so I created a Page item (copied it) and set it to hidden. As for source I am using Always replace any existing value in session but then I am not sure what to use for source type? I mean I don't want to assign anything as I am doing that in After Header Process (PL/SQL Anonymous block) and I can't find a way of doing that?

    And I think that Hidden fields are saved in the session, I can see other items with values in the session debug which are Hidden.

    --Andy

    Edited by: A Tael on Mar 19, 2013 1:57 PM
  • I'm sure I left all that blank or defaulted. Since the value is assigned by a process, I believe none of that is required. But setting "always" as you did is generally good.

    Howard
  • Howard (... in Training)
    Howard (... in Training) Member Posts: 905
    edited Mar 19, 2013 3:18PM
    This always gives me grief. It's difficult to debug because 1) the Radio Group is not immediately saved in the session state AND 2) you cannot see the Hidden Item value on screen to know if your code is working. Here's what I recall.

    1) You might want a Dynamic Action triggered by the event which is a change in the Radio Group. Use that DA to save the Radio group value in the session state. Otherwise, I'm afraid the :Pxx_RADIO value being tested might not be the current one -- i..e., the one in HTML that you see on the screen.

    *** Edited by: Howard (... in Training) on Mar 19, 2013 3:17 PM (NOTE!)
    We'll that will submit the whole page so I have to check what I've done before to just submi this item.

    2) You might start with :Pxx_RADIO_LAST as a regular TEXT field so you can see it and do any verification and debugging. Then once it's working change to a Hidden Item or hide it with some Dynamic Action on Page Load.

    I need to verify this ... busy today.

    Howard
  • Howard (... in Training)
    Howard (... in Training) Member Posts: 905
    edited Mar 19, 2013 4:04PM
    Okay.

    1) For the Dynamic Action:
    You want the Action to be "Execute PL/SQL Code".
    Under Settings, in the code window just put the single "null;" satement.
    Under Settings, for Page Items To Submit - Pxx_RADIO -- note - no colon here!
    Under Setitngs, for Page Items to Return - Pxx_RADIO_LAST -- not no colon here!
    (And don't put both Items on both line because that just causes a lock up when executed.)

    2) The only down side is that if you display Pxx_RADIO_LAST, it will not show it's value until the Pxx_RADIO is change and the values is return in the Dynamic Action. But as soon as it's returned, it's the old value of Pxx_RADIO. And if Pxx_RADIO is toggled, Pxx_RADIO_LAST remains that initial value that it was when first set. If you want to see Pxx_RADIO_LAST on the screen when the page renders, I suppose tou need a DA to save it to the session state when it's set in the before header process.

    If you want, look here on p. 5.

    Workspace: SIMPLE_DEMOS
    UN: hcarson at woh.rr.com
    PW: SD123456789

    RADIO_DEMO ID:25096
    Dever / Ima9Dever

    Page 3: Radio Group
    Page 4: Checkbox
    Page 5: Hidden Item Demo

    To see that the value is saved, Set Radio Group to "Yes" and then go to p. 4. Go back to p.5 and "Yes" will be still be set but the Text Field -- I changed to Text from Hidden -- will be blank. When you click No, then the "Pxx_RADIO_LAST" value of Y will appear here. (Make sense?)

    Howard
  • 20378
    20378 Member Posts: 577
    Thanks! I will try this solution.

    I have figured out that it has to do with the Radio Button to do (I think) as if I assign any other value to my XX_LAST Item it works like a charm.

    --Andy
This discussion has been closed.