SQL script to start the concurrent program "Workflow Background Process" as SYSADMIN user.
Dont run the script as-is, test and modify it to your needs. Very handy script when developing/testing.
Any improvements you can imagine? Let me know.
set serveroutput on
set lines 150 tab off verify off
declare
l_request_id fnd_concurrent_requests.request_id%type;
l_prog_app fnd_application.application_short_name%type;
l_prog fnd_concurrent_programs.concurrent_program_name%type ;
v_msg varchar2(1000);
l_phase varchar2(1000);
l_status varchar2(1000);
l_dev_phase varchar2(1000);
l_dev_status varchar2(1000);
l_message varchar2(1000);
l_done boolean;
begin
dbms_output.put_line ('--------------------------------------------------');
if '&1' is null
then
dbms_output.put_line ('--------------------------------------------------');
dbms_output.put_line ('Wrong use ... enter an item itemtype, for example :');
dbms_output.put_line ('@wfbg_start.sql APINVAPR N');
dbms_output.put_line ('--------------------------------------------------');
else
-- user : SYSADMIN
begin
INSERT INTO fnd_sessions SELECT USERENV('sessionid'),TRUNC( SYSDATE ) FROM DUAL WHERE NOT EXISTS( SELECT NULL FROM fnd_sessions WHERE session_id = USERENV('sessionid'));
fnd_global.apps_initialize( user_id=>0, resp_id=>20420, resp_appl_id=>1, security_group_id =>0);
fnd_client_info.setup_client_info( application_id=>1, responsibility_id=>20420, user_id=>0, security_group_id =>0);
end;
dbms_output.put_line ('--------------------------------------------------');
dbms_output.put_line ('- Apss session for SYSADMIN ');
dbms_output.put_line ('--------------------------------------------------');
select (select application_short_name from fnd_application where application_id = cp.application_id)
, concurrent_program_name
into l_prog_app, l_prog
from fnd_concurrent_programs cp
where concurrent_program_name = 'FNDWFBG';
dbms_output.put_line ('l_prog_app = '||l_prog_app);
dbms_output.put_line ('l_prog = '||l_prog);
l_request_id := fnd_request.submit_request(application => l_prog_app
, argument1 => '&1'
, argument2 => null
, argument3 => null
, argument4 => 'Y'
, argument5 => 'Y'
, argument6 => 'Y'
, description => 'Workflow Background Process (automatically)'
, program => l_prog
, start_time => sysdate
, sub_request => NULL
);
dbms_output.put_line ('Request_id = '||l_request_id);
if l_request_id = 0 then
FND_MESSAGE.RETRIEVE(MSGOUT => v_msg);
dbms_output.put_line ('ERROR : '||v_msg);
else -- succes
commit;
if '&2' is null then
dbms_output.put_line ('--------------------------------------------------');
dbms_output.put_line ('- Not waiting for request to finish ...');
dbms_output.put_line ('--------------------------------------------------');
elsif '&2' = 'Y' then
dbms_output.put_line ('--------------------------------------------------');
dbms_output.put_line ('- Waiting for request to finish ...');
dbms_output.put_line ('--------------------------------------------------');
l_done := fnd_concurrent.wait_for_request
( request_id => l_request_id
, interval => 10 -- Kijk om de 60 seconden
, max_wait => 6000 -- Wacht maximaal 2 uur
, phase => l_phase
, status => l_status
, dev_phase => l_dev_phase
, dev_status => l_dev_status
, message => l_message
);
dbms_output.put_line ('l_phase = '||l_phase);
dbms_output.put_line ('l_status = '||l_status);
dbms_output.put_line ('l_dev_phase = '||l_dev_phase);
dbms_output.put_line ('l_dev_status = '||l_dev_status);
dbms_output.put_line ('l_message = '||l_message);
else
dbms_output.put_line ('--------------------------------------------------');
dbms_output.put_line ('- Not waiting for request to finish ...');
end if;
end if;
end if;
dbms_output.put_line ('--------------------------------------------------');
end;
/