This discussion is archived
7 Replies Latest reply: Nov 14, 2012 9:00 AM by MLBrown RSS

Code for Alert

893566 Newbie
Currently Being Moderated
Hi

I created an Alert for an update as "update y/n" with two buttons Button1 = Yes and Button 2 = No. When the alert is raised in the form and when the user selects yes/No I would like to capture the selection and make aprropriate changes like if the user says yes I would like to run a procedure or if the user says no I would like the alert to be closed and previous window be displayed. How can I achieve this. Please help me with sample code
  • 1. Re: Code for Alert
    MLBrown Journeyer
    Currently Being Moderated
    You would put code like this in once the button is pressed.
    declare
      v_alert         alert;
      button_pressed  number(12);
    begin     
      --
      -- Display the alert
      --    
      v_alert := FIND_ALERT('NAME_OF_ALERT');  -- Whatever you named your alert
      button_pressed := show_alert(v_alert);
      
      --
      -- If the button you set up as button 1 is pressed then do this
      --
      if button_pressed = ALERT_BUTTON1 then
        CALL_A_PROCEDURE;    -- Whatever the name of your procedure is
      else
        raise form_trigger_failure;  -- Stop processing and go back to where you were before all this happened
      end if; 
  • 2. Re: Code for Alert
    893566 Newbie
    Currently Being Moderated
    Hi

    I wrote the follwiing code in the when button pressed trigger for a button(UPDATE button)
    DECLARE
         ALERT NUMBER;
         button_pressed number(12);

    BEGIN
    ALERT := SHOW_ALERT('UPDATE_ALERT');

    if button_pressed = ALERT_BUTTON1 then
    MESSAGE('YES');
    else
    raise form_trigger_failure; -- Stop processing and go back to where you were before all this happened
    end if;

    END;

    but it does not work. Please help me achieve this
  • 3. Re: Code for Alert
    MLBrown Journeyer
    Currently Being Moderated
    Are you getting an error? What is happening when the button is pressed?
  • 4. Re: Code for Alert
    MLBrown Journeyer
    Currently Being Moderated
    Change your declaration from:
    DECLARE 
      ALERT              NUMBER;
      button_pressed     number(12);
    to this:
    DECLARE 
      V_ALERT           alert;
      button_pressed  number(12);
    because you need to declare the alert and you cannot use ALERT as a variable because it is a reserved word.

    Then change your
    ALERT := SHOW_ALERT('UPDATE_ALERT');
    to this:
      V_ALERT := FIND_ALERT('UPDATE_ALERT');  
      button_pressed := SHOW_ALERT('UPDATE_ALERT');
    because you need to find the alert before you evaluate which button was pressed.

    It should work fine after that.

    Your final code should look like:
    DECLARE 
      V_ALERT           alert;
      button_pressed  number(12);
    BEGIN
      V_ALERT := FIND_ALERT('UPDATE_ALERT');  
      button_pressed := SHOW_ALERT('UPDATE_ALERT');
      
      if button_pressed = ALERT_BUTTON1 then
        MESSAGE('YES');
      else
        raise form_trigger_failure;  -- Stop processing and go back to where you were before all this happened
      end if;
    END;
  • 5. Re: Code for Alert
    893566 Newbie
    Currently Being Moderated
    Thank you. Also I would like to have the alert display some values like when I click on a button the I would like to have a pop up which would display the values I enterd in the form like

    You have entered your name : XYZ

    How can I achieve this
  • 6. Re: Code for Alert
    Andreas Weiden Guru
    Currently Being Moderated
    Check the onlinehelp for SET_ALERT_PROPERTY.
  • 7. Re: Code for Alert
    MLBrown Journeyer
    Currently Being Moderated
    I'm not exactly sure what you mean. If you are talking about displaying the message in the alert, then Andreas is right you could use the SET_ALERT_PROPERTY built-in to control the TITLE and the ALERT_MESSAGE_TEXT (message that is displayed) in the alert.
      set_alert_property('UPDATE_ALERT',ALERT_MESSAGE_TEXT, 'You have entered your name ' || :xyz);

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points