0
votes

I am trying to set a value of a page element on page load in the beginning. The value is dependent on another element that has already been retrieved from the DB and is already set at the beginning.

To set the id I created a function and I call this function for the dynamic action on page load like this:

declare
id number;

begin

id:= set_ID(V('P1_page_item')); 
apex_util.set_session_state('P17_ID',id);

end;

However the value for the page item is not being set. Do you have any suggestions how an page item value can be set on page load?

2

2 Answers

0
votes

There are many ways to set the value of a page item on page load. You can use a page process, a computation, a default value for the page item or a source value for the page item. A dynamic action is a possibility as well, but I have never done that...

Personally I find a computation the cleanest way of setting a value to a page item. It is meant just for that - computing a value for an item. In your case, you could create a computation for item P17_ID of type expression with source set_ID(:P1_PAGE_ITEM)

Now the problem of the page item not being set is probably something else. Try to give as much information as possible about the page to give us clues as to why this is not being set correctly. Have you run the page in debug ? That should give you an idea of what is happening.

On a side note:

  • The function V should not be used in an application. It was created to allow referencing of apex item values outside of the context of an application, for example in a stored procedure or a view. Using the V function has performance issues and should be avoided if possible. In the application, just use the bind variable syntax (:P1_ITEM) to reference and set variable values.
  • How is P1_PAGE_ITEM being set ? As a best practice try to avoid referencing page items on other pages. P1_PAGE_ITEM should only be referenced and manipulated on page 1 and so on. Using branches or links you'd then set a corresponding item P17_PAGE_ITEM on page 17. This will save you a lot of debugging time later on. Also, if you clear cache on page 1, then the value of P1_PAGE_ITEM will be wiped out which could lead to unexpected behaviour if that page item exists on other pages.
0
votes

I'd use

id := set_ID(:P1_PAGE_ITEM); 

Also, did you set dynamic action to fire on initialization? I presume you should.