Friday 5 April 2013

Submitting XML Report using FND_REQUEST Package

FND_REQUEST.SUBMIT_REQUEST submits concurrent request:

1.  If you submit the concurrent Program (XML Report) through back and  as  normal way using “FND_REQUEST. SUBMIT_REQUEST”, it will not take Attached Template(Layout) to the Concurrent Program. This we can observe in SRS Window -> View Details -> Options below Screen will appear.
1
 2.  If you want to appear Template to the Concurrent Program, we need to add Layout Explicitly using “FND_REQUEST.ADD_LAYOUT” Packaged Procedure. Before submitting the Concurrent Program (XML Report). (See given example code below)
3. After Completion of Point 2, Template details we can see in SRSàView Details à Options in below Screen.
2


--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);

--CODING

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;



--- Final Coding  --

DECLARE
   l_request_id               NUMBER;
   l_user_id                  NUMBER         := NULL;
   l_resp_id                  NUMBER         := NULL;
   l_resp_appl_id             NUMBER         := NULL;
   l_user_name                VARCHAR2 (255) := 'RAGHAVENDRA';
   l_responsibility_name      VARCHAR2 (255)
                             := 'Order Management Super User, Vision Germany';
   l_printer_name             VARCHAR2 (255) := 'PN Printer';
   l_warehouse_id             NUMBER         := 911;
   l_application_short_name   VARCHAR2 (10)  := 'WSH';
   l_option_return            BOOLEAN;
BEGIN
   BEGIN
      SELECT fu.user_id
        INTO l_user_id
        FROM fnd_user fu
       WHERE fu.user_name = l_user_name;

      SELECT frt.application_id, frt.responsibility_id
        INTO l_resp_appl_id, l_resp_id
        FROM fnd_responsibility_tl frt
       WHERE frt.LANGUAGE = 'US'
         AND frt.responsibility_name = l_responsibility_name;
   EXCEPTION
      WHEN NO_DATA_FOUND
      THEN
         l_resp_appl_id := '';
         l_resp_id := '';
         l_user_id := '';
   END;

   fnd_global.apps_initialize (user_id           => l_user_id,
                               resp_id           => l_resp_id,
                               resp_appl_id      => l_resp_appl_id
                              );
   /* Adding Template to the Concurrent Program */
   /* Note : We need to Explicitly add Template to the Concurrent Program before submitting **/
   l_option_return :=
      fnd_request.add_layout (template_appl_name      => l_application_short_name,
                              template_code           => 'BLINKWSHRDPAK1',
                              template_language       => 'En',
                              template_territory      => 'US',
                              output_format           => 'PDF'
                             );
   /* Setting Printer Options , if we want print output of the Concurrent Program on Particular Printer*/
   l_option_return :=
      fnd_request.set_print_options (printer             => l_printer_name,
                                     style               => 'LANDSCAPE',
                                     copies              => 1,
                                     save_output         => TRUE,
                                     print_together      => 'N'
                                    );
   l_request_id :=
      fnd_request.submit_request (application      => 'WSH',
                                  program          => 'BLINKWSHRDPAK1',
                                  description      => 'Blink Using Fnd Request ',
                                  start_time       => SYSDATE,
                                  sub_request      => FALSE,
                                  argument1        => l_warehouse_id,
                                  argument2        => 10000,
                                  argument3        => 'N',
                                  argument4        => 'B',
                                  argument5        => 'DRAFT',
                                  argument6        => 'BOTH',
                                  argument7        => 'INV',
                                  argument8        => NULL,
                                  argument9        => NULL,
                                  argument10       => NULL,
                                  argument11       => '2',
                                  argument12       => 'Y'
                                 );
   DBMS_OUTPUT.put_line ('Request ID:' || l_request_id);
   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      NULL;
END;

3 comments: