Redirect to page stored in table

Viewed 172

I have an application in which a user creates a form, for which several responsible persons are selected in this form and can edit this form.

As soon as the form is submitted, the corresponding page of the process is changed. The page of the form and the respective responsible persons are saved in a separate table. The function has to check whether the logged-in user with the user ID is entered in the table as one of the responsibles. The table for example Responsible1 contains a foreign key to the table USERS, in which the ID is located. As soon as it finds the responsible in the table, the function then should redirect the user to the corresponding page.

create or replace function forward_user(p_username in varchar2)
return varchar2
is
l_user varchar2(255);
l_branch_page number;

begin
l_user :=p_username;
 /*
    Get the target page depending on entry in table 
  */
select 
 page
 into l_branch_page
from 
FORM_PAGES  
where EXISTS (SELECT f.RESP1 from FORM f
left outer join RESPONSIBLE1 s on s.RESP1=f.RESP1
LEFT OUTER JOIN USERS u on u.ID=s.ID where lower(u.USERNAME) =lower(l_user)  )
OR (fp.RESP2 in
(SELECT f.RESP2 from FORM f 
left outer join RESPONSIBLE2 p on p.RESP2=f.RESP2
left outer join USERS u on u.ID=p.ID where lower(u.USERNAME) =lower(l_user) ))
OR (fp.RESP3 in (select f.RESP from FORM f 
left outer join RESPONSIBLE3 e on e.RESP3=f.RESP3
left outer join USERS u on u.ID=e.ID where lower(u.USERNAME) =lower(l_user) ));

return APEX_PAGE.GET_URL(p_page =>l_branch_page);

exception
  when no_data_found then
   /*Use current page as default page*/ 
   return APEX_PAGE.GET_URL(p_page =>1);
   end ;

I then call this function in a pl/sql process when the button NEXT is clicked.

DECLARE
x varchar2(4000);
BEGIN
x:=forward_user(:session_user_name);
END;

I have already checked the sql statements and they work fine, I get the corresponding page. As well the function compiles successfully. But when I click the button nothing happens, the user is not forwarded to the stored page in the table.

As well I tried to call this function in a branching process with the behaviour Function Returning a URL(Redirect) but as well nothing happens.

Can someone help me here?

1 Answers

My suggestion would be:

  • create a hidden page item (as you're on Page 1, let's call it P1_URL)

  • you already have a process which runs when the Submit button is pressed. Its execution point should be "Processing". Rewrite the process so that it populates P1_URL, e.g.

    declare
      l_branch_page number;
    begin
      -- your query goes here; I'll redirect to page 4
      l_branch_page := 4;
      :P1_URL := APEX_PAGE.GET_URL(p_page => l_branch_page);
    end;
    
  • create an After Processing branch (why? So that process (see above) first populates P1_URL item). Its behavior's type should be "Page or URL (Redirect)", and its target should be &P1_URL. (literally that - ampersand followed by P1_URL followed by dot).

That's all; when you push the Submit button, process will populate P1_URL item which will be used by the branch and redirect to desired page. Will it work? It worked for me, I've just tested it.


Function:

function forward_user (p_username in varchar2)
  return varchar2
is
  ...
  return apex_page.get_url(p_page => l_branch_page);
end;

Process: just one line:

:P1_URL := forward_user(:session_user_name);
Related