Friday, July 11, 2014

Submitting concurrent program using FND_REQUEST.SUBMIT_REQUEST along with XML Publisher layout and printer options

FND_REQUEST.SUBMIT_REQUEST is to submit a concurrent program.

Using fnd_request.submit_request,will only submits the program and will not attach any layout or print option. Code below will help you to set XML publisher template/layout along with print option.

*****Add_layout and Add_printer procedures are optional in calling submit_request. Use only if you need to set them.(Based on requirement)

--Layout is submitted to a concurrent request using below procedure.

fnd_request.add_layout (
                    template_appl_name   => 'Template Application',
                    template_code            => 'Template Code',
                    template_language      => 'en', --Use language from template definition
                    template_territory       => 'US', --Use territory from template definition
                    output_format            => 'PDF' --Use output format from template definition
                     );

--Setting printer while submitting concurrent program

fnd_submit.set_print_options (printer      => lc_printer_name
                                             ,style        => 'PDF Publisher'
                                           ,copies       => 1
                                               );

fnd_request.add_printer (
                    printer => printer_name,
                    copies  => 1);

Example1:

DECLARE
   lc_boolean           BOOLEAN;
   ln_request_id       NUMBER;
   lc_printer_name   VARCHAR2 (100);
   lc_boolean1         BOOLEAN;
   lc_boolean2         BOOLEAN;
BEGIN

  -- Initialize Apps 
      fnd_global.apps_initialize (>USER_ID<
                                             ,>RESP_ID<
                                             ,>RESP_APPL_ID<
                                             );

  -- Set printer options
   lc_boolean :=
      fnd_submit.set_print_options (printer      => lc_printer_name
                                                    ,style        => 'PDF Publisher'
                                                  ,copies       => 1
                                                   );

  --Add printer
   lc_boolean1 :=
                fnd_request.add_printer (printer      => lc_printer_name
                                                    ,copies       => 1);
 --Set Layout
  lc_boolean2 :=
               fnd_request.add_layout (
                            template_appl_name   => 'Template Application',
                            template_code            => 'Template Code',
                            template_language       => 'en', --Use language from template definition
                            template_territory        => 'US', --Use territory from template definition
                            output_format             => 'PDF' --Use output format from template definition
                                    );
   ln_request_id :=
      fnd_request.submit_request ('FND',                -- application
                                  'COCN_PGM_SHORT_NAME',-- program short name
                                  '',                   -- description
                                  '',                   -- start time
                                  FALSE,                -- sub request
                                  'Argument1',          -- argument1
                                  'Argument2',          -- argument2
                                  'N',                  -- argument3
                                  NULL,                 -- argument4
                                  NULL,                 -- argument5
                                  'Argument6',          -- argument6
                                  CHR (0)               -- represents end of arguments
                                 );
   COMMIT;

   IF ln_request_id = 0
   THEN
      dbms.output.put_line ('Concurrent request failed to submit');
   END IF;
END;

Example2:

Scheduling/Adding Layout/Delivery Options.

declare
l_conc_id     number;
l_boolean     boolean;
e_add_del     exception;
e_add_layout  exception;
e_set_option  exception;
e_set_repeat  exception;
begin
   -- intialize the apps.
   fnd_global.apps_initialize (<user_id>,<resp_id>,<resp_app_id>);

   -- Adding delivery option to send the request output as email
   l_boolean := fnd_request.add_delivery_option
                   (type => 'E' -- this one to speciy the delivery option as email
                   ,p_argument1 => 'Delivery Option Test' -- subject for the mail
                   ,p_argument2 => 'xyz@ab.bc.uk' -- from address
                   ,p_argument3 => 'rty@ab.bc.uk' -- to address
                   ,p_argument4 => 'klm@ab.ac.uk' -- cc address to be specified here.
                   ,nls_language => ''); -- Optional

   -- Adding Template to the request
   if l_boolean then
      l_boolean := fnd_request.add_layout
                     (template_appl_name => 'XXAK'
                     ,template_code      => 'XX_TEST_FND_REQUEST'
                     ,template_language  => 'en' -- English
                     ,template_territory => null
                     ,output_format      => 'PDF'
                     );
   else
      raise e_add_del;                                              
   end if; 

   if l_boolean then
      l_boolean := fnd_request.set_options ('YES');
   else
      raise e_add_layout;
   end if;

   -- Scheduling the request
   if l_boolean then
      l_boolean :=fnd_request.set_repeat_options
                     (repeat_time     => null--to_char(sysdate,'hh24:mi:ss'),
                     ,repeat_interval => 2   --Applies only when releat_time is null
                     ,repeat_unit     => 'MINUTES'--Applies only when releat_time is null
                     ,repeat_type     => 'START' --Applies only when releat_time is null
                     --,repeat_end_time  =>
                     --,increment_dates  => 'Y'-- Increment the date parameters for next run
                     );
   else
      raise e_set_option;                                                
   end if;
                                  
   if l_boolean then
      l_conc_id := fnd_request.submit_request
                      (application => 'XXAK'
                      ,program     => 'XX_TEST_FND_REQUEST'
                      ,start_time  => null
                      ,sub_request => null
                      ,argument1   => <argument1>
                      ,argument2   => <argument2>
                         );
   else
      raise e_set_repeat;                                             
   end if;
  
   if l_conc_id > 0 then
      dbms_output.put_line('Concurrent Program Id: '||l_conc_id);
   else
      dbms_output.put_line('Error: submit_request');
   end if;
   commit;
exception
   when e_add_del then
      dbms_output.put_line('Error: add_delivery_option');
   when e_add_layout then
      dbms_output.put_line('Error: add_layout');
   when e_set_option then
      dbms_output.put_line('Error: set_options');
   when e_set_repeat then
      dbms_output.put_line('Error: set_repeat_options'); 
   when others then
      dbms_output.put_line('Error: '||sqlerrm);      
end;


Challa.

No comments:

Post a Comment