This discussion is archived
5 Replies Latest reply: Nov 20, 2012 2:41 PM by 909599 RSS

After popupURL,needs to close window,submit value,and redirect other window

LC Newbie
Currently Being Moderated
Hi,

I am using APEX 4 for the development.

Use the following URL target in my main page-

javascript:popupURL('f?p=&APP_ID.:99:&APP_SESSION.::&DEBUG.::P99_PORT_ACC_HEAD_TAX_ID:&P20_PORT_ACC_HEAD_TAX_ID.',300,300);

This opens up page 99. In page 99, I need to collect some require information. Once, a user click on "submit" button in the popup window, the following actions are needed:

1. A database column update to the new value ... create a process, but, it doesn't work since the page is closing not submitting.
2. close the popup window, which I am using javascript:window.close();
3. Redirect the original page 20 to page 15

Can someone please give some advise?

Thank you,
Ling
  • 1. Re: After popupURL,needs to close window,submit value,and redirect other window
    vee Guru
    Currently Being Moderated
    On of many ways
    <li>Create a branch in the parent page that runs conditionally on a request value, say when request equals 'POPUP_CLOSED'. You can make this branch run before any process, so it immediately proceeds with branch after submit(if the request matches).

    <li> Now add a javascript function in the same page(parent), its purpose is to submit the page with a request(which inturn causes the branch)
    function submit_for_redirect(){
      apex.submit('POPUP_CLOSED');
    }
    Make sure that the branch works fine by running the javascript function submitfor_redirect()_ , at the same time ensure that the rest of the page processing works the way it was.

    <li>Now in the popup page, wherever you are calling the window.close method(could be a button,could be onload JS) modify it so that the parent page's function is called first
    javascript:window.parent.submit_for_redirect();window.close();
    That should the parent page processing before closing the child page(effectively would work as though they were running in parallel).Hope I have made it clear enough for you.
  • 2. Re: After popupURL,needs to close window,submit value,and redirect other window
    LC Newbie
    Currently Being Moderated
    Hi Vee,

    Thank you for the response.

    I haven't tried that yet...but, wonder if you can help me with my method first.

    Now, the only thing that is not working for me is the update process in the popup window.

    In the popup window, I can use the following script for URL Target in submit button:
    javascript:window.opener.location.reload();window.close();

    Do you know how I can run a database update after user enter the data and before the popup window closes ?
    If I can make this work, reload the parent page will do the trick for my process.

    Thank you!
    Ling
  • 3. Re: After popupURL,needs to close window,submit value,and redirect other window
    vee Guru
    Currently Being Moderated
    If you are on apex 4, create a Dynamic Action that runs on the button press
    <li>With the first true action running the required PLSQL code(make sure you add the changed page items to the"Page Items to Submit field" )
    <li>The second true action can be of Js code and put in your code.

    -----------------------
    Another slightly trickier way (but works with all apex versions) is to generate the JS code in PLSQL

    So your Button(in the popup page) submits the page
    You will have a PLSQL process that does the necessary processing on the button press.
    After all the processing you add somee code that generates the JS code

    It would be like
    BEGIN
     /* Do your PLSQL Processing here */
     
     /*Js Code to close page etc
      Note that this code will be run only after the PLSQL and on the next page load, don't try to mix up JS and PLSQL expecting a JS code(between two PLSQL blocks) to run between the PLSQL blocks. Remember JS runs in browser and PLSQL in server, so all JS code waits till page is reloded
     */
     htp.p('<script>');
     htp.p('window.opener.location.reload();window.close();');
     htp.p('</script>');
    END;
    ---------------------------------------------------

    Another method, is to add the JS code to an onload function executing it only conditionally say when a page item is set with a specific value. You set that page item with that value only after the PLSQL block completes, hence the JS code runs only after processing and not on every load.

    Use any of these methods depending on what feels easy/comfortable to you.
  • 4. Re: After popupURL,needs to close window,submit value,and redirect other window
    LC Newbie
    Currently Being Moderated
    Thank you again! I used the "tricker way" and that works perfectly for my process. :)
  • 5. Re: After popupURL,needs to close window,submit value,and redirect other window
    909599 Newbie
    Currently Being Moderated
    vee, Thank You very much!
    Third method helped me.

    I didn't use the first approach because my process uses the variable apex_application_g_f which isn't accessable from Dynamic Actions(AJAX), AFAIK.
    And the second method doesn't work for my 'on submit' process.

    But the third method crutched me.
    Thank You, vee

    --Sasha                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Legend

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