Skip to main content

Returning a Value from a Popup Page

I just ran into a situation where I needed to pass back a value from a pop-up page to a tabular form item in the calling page. While I've done this in the past ny manually writing all of the JavaScript, I thought that I'd take a look at the new documented APEX JavaScript APIs.

I came across this function in the APEX 3.2 API Reference Guide (Part #E13369-01):

$v_PopupReturn(pValue, pThat)
Sets the value of the item in the parent window (pThat), with (pValue) and then
closes the popup window.
Return Value
Not applicable.
pValue (string)
pThat (DOM node | string ID)

Looks perfect!  In addition to passing the value back, it will also close the pop-up page, even though that is not documented.

On the pop-up page, I created a link with an Optional Redirect to URL, and put the following in the link:

javascript:$v_PopupReturn(#EMPNO#, '&P3_NODE.')

P3_NODE is the DOM ID of the tabular form item that I wanted to return the value to.  You'll need to make sure that it's formatted properly for this to work.  Thus, I am passing in a "1", but returning "f03_0001".  A simple computation can do the trick.

Since we're using a built-in tabular form, we need to put the calling JavaScript in the Element Attributes of the item that we want the popup form to set.  I used this:

onclick="popUp2('f?p=' + $v('pFlowId') + ':3:' 
+ $v('pInstance') + '::::P3_NODE:#ROWNUM#',250,600);" readonly

This will pop open a new window, based on page 3 of my application.  It will also grab the Application ID and Session ID from the DOM and use those in the link, so that we preserve our session state.  Finally, it will pass along the corresponding ROWNUM of the item that we clicked on to the item P3_NODE - where I will make the proper transformation with the computation on Page 3.  Lastly, the readonly option prevents users from making direct changes to the item.

Point taken from this - have a look at the APEX API guide before you embark on writing your own code.  There are a number of helpful functions there than can save a lot of time and hassle.


Taj said…
Nice. Just 2 weeks back I was looking for this kind of functionality. Didn't realize it is available in 3.2 version. I had to write my code (we are on 3.1.2).

Guess, one more reason to update to the newest version.

Thanks -Scott- for sharing.

OraDude said…

"$v_PopupReturn(pValue, pThat)
Sets the value of the item in the parent window (pThat), with (pValue) and then
closes the popup window."

You wrote:

"it will also close the pop-up page, even though that is not documented."

Assuming the first is a copy-paste from the documentation, I think your statement needs revision :-)
Scott said…
Nah, I just need to drink more coffee before posting blog entries. :)

Thanks for the correction.

- Scott -
You can also use JQuery modal dialogs to achieve the same result. It will probably look nicer :)

Scott said…
Sure, you can use jQuery, but the solution that I outlined does not rely on any additional components, making it a lot more portable and simple. Sure, it may not look as good, but it took less than 10 minutes to implement from start to finish.


- Scott -
Anonymous said…
Nice Post.
Do you have any applications where I can see how this has been implemented?
I am using APEX 4.0.Can we use the same in 4.0 too?
Scott said…
Sorry, I don't have a working example. It should still work in 4.0, but there may be a better way to do it.

- Scott -
AI said…
Hi Scott, If you were to return value back to parent page where parent page item was a pop-up LOV, how would it work?

In my case its just blank. The page closes so I know it works.

Hi, Thanks for this post :) It was so useful, I'm working on apex 4.2 and as you said in a comment, "there may be a better way to do it" But this one is working excellent, and combined with Dynamic actions, I can create a Popup report ¿? :P something like a Popup LOV but showing a report instead of a list of links, it looks so much better and takes not much time.

Popular posts from this blog

Thanks, ODC (Oracle Developer Community)!

I owe a lot of thanks to the ODC - which stands for Oracle Developer Community.  What is ODC?  You may remember it as OTN, or the Oracle Technology Network.  Same people, different name.  Why they changed it I can't say.  People just liked it better that way... (love that song)

In any case, what am I thankful for?  A lot.  To start, the tools that I use day in and day out: SQL Developer, ORDS, Oracle Data Modeler, SQLcl and - of course - APEX.  Without these tools, I'm likely on a completely different career path, perhaps even one that aligns more closely with my degree in television management.

While the tools are great, it's really the people that make up the community that make ODC stand out. From the folks who run ODC and the Oracle ACE program to the developers and product managers who are behind the awesome tools, the ODC community is one of, if not the greatest asset of being involved with Oracle's products.

If you have yet to get more involved with this communi…

Spaced Out

A while back, I wrote about how to give the Universal Theme a face lift.  If you follow the steps in that post, the base font for an APEX application with the Universal Theme can easily be changed.

While that's all well and good, sometimes you only want to change the font for a report, not the entire page.  One of the applications that I'm building contains a number of IRs based mostly on log data.  Thus, having that data in a monospaced font would make it a whole lot easier to read.

You can search Google Fonts for monospaced fonts by selecting only that option on the right-side menubar.  You can also opt for the standard yet kinda boring Courier and achieve the same thing.

To implement this in your application, follow the steps in my other post, but stop shy of the final step.  Instead of pasting in the text that I specify, paste in the following to the Custom CSS field in Theme Roller, using the name of the font you selected for the font-family:

.a-IRR-table tr td { font-fam…

Whose Deck is it Anyways?

This year at KScope, we're going to try something new.  And fun.  And funny to watch - we hope.  It's called "Whose Deck is it Anyways?", and will occur on Sunday at 8:30pm.  It's only 30 minutes, but it will likely be the best 30 minutes of the conference.  Or at least the most embarrassing.

Here's what we're going to do: the will be four 5-minute presentations - one on each of the following: BI, EPM, Database & APEX.

Sound interesting?  Probably not.  We get that, too.  So here's what we did.

Each 5-minute session will be presented by a non-expert.  For example, it's highly likely that I'll be presenting on BI or EPM.

To make it even better, each slide deck will be prepared by the corresponding expert.  So again, it's highly likely that my slide deck's creator will be either Stewart Bryson or Edward Roske.  If nothing else, this session will be a crash course in how not to make cohesive, easy to read slides.

Interested now?  Ya,…