Warm tip: This article is reproduced from stackoverflow.com, please click
oracle-apex

APEX_ITEM POPUP referencing another apex_item

发布于 2020-03-27 10:22:05

I have a page with a couple of items and a PLSQL Dynamic content.

The Dynamic content, as its name implies generates a bunch of dynamic items, how many and what they are is dynamic, I get them from a table.

Quite a few of them are POPUP_FROM_QUERY items where the QUERY is also taken from a table. This works well for most things, but a few are such that the QUERY references another dynamically generated item(as in, I generate items for dept and for name, you select a dept, the name item only shows names in that dept).

The code looks something like this:

  htp.p ((APEX_ITEM.POPUP_FROM_QUERY (p_idx => 2, p_value => '', p_item_id => 'dept_name', p_lov_query => 'SELECT dept department, dept_id id FROM departments WHERE dept_location = ''USA''', p_item_label => 'dept_name')));

  htp.p ((APEX_ITEM.POPUP_FROM_QUERY (p_idx => 2, p_value => '', p_item_id => 'emp_name', p_lov_query => 'SELECT emp emp_name, emp_id id FROM employees WHERE department = :dept_name', p_item_label => 'emp_name')));

I only put the relevant lines here, there are actually trios of lines, one with p_idx = 1, and one with p_idx = 4(apparently you need to leave one for the LOV) but these are all display only. When saving I reference them with apex_application.g_f01(i) where you replace 1 for the p_idx.

I have tried replacing the :dept_name with just about everything. apex_application.g_f02(1), dept_name(the p_item_id), g_f02(1), f02(1), f02_0001(when inspecting the item in consol this shows as id). I have tried all these and all these with ':' in front. I have also tried them just included in the parentheses of the select, and by doing 'select ..... where ..= ' || :dept_name || ''''. None of this seems to work, and I couldn't find anything online or within the documentation for APEX_ITEM

Questioner
TineO
Viewed
46
TineO 2019-07-03 22:18

Since no one answered I worked on it till I came to a somewhat simplistic solution that works, although it's not perfectly dynamic as you will see later.

All the dynamically generated items have ids like f02_0000 where the 02 is the idx of the item and the 0000 is the row(the first item it generates is 0000, the second is 0001,...)

I made a bunch of hidden items on the page and the same number of application items, and named them all in sequence(ITEM_1, ITEM2,...)

Then I made a Dynamic Action on the page, Event : Change, Selection Type: jQuery Selector, jQuery Selector: input[name = "f02"] --all the apex_items you enter are p_idx => 2 in my scenario.

This DA has a Javascript action that gets the number of the triggering element with

parseInt(this.triggeringElement.id[this.triggeringElement.id.length -1])

This of course only gets the last number of the id, but changing this is easy.

Then I also have an action here that assigns the value of the page item to its corresponding application item.

:APPLICATION_ITEM_1 := :ITEM_1;

Where I also put all the items into Items to Submit

And then I change all the LOVs to use the corresponding application items.

I did some extra things like clearing all the page and application items on refresh and such, but you can play around with this.

This works, but its a bit of a dirty solution as you need to make it work for however items you generate. So if you know you will only generate up to a certain amount of items, this will be fine, if it can go up to a ridiculous amount of items, then you need a different solution.