Tuesday 22 January 2013

R12 Supplier Contact creation API


AP_SUP_SITE_CONTACT_INT interface used in 11i for loading supplier contact. Currently in R12 contacts can not be loaded using the interface table.

ap_vendor_pub_pkg.create_vendor_contact API is used in R12 and the program has to be registered as a concurrent program.
### Sample R12 Code    

BEGIN
     v_party_usg_assignment_id := NULL;
      v_relationship_id := NULL;
      v_directional_flag := NULL;
      v_rel_rowid := NULL;
      fnd_file.put_line (fnd_file.LOG,
                            'Vendor code :'
                         || rec.vendor_name
                         || '  Vendor site code :'
                         || rec.vendor_site_code
                         || '  Person Last Name : '
                         || rec.person_last_name
                        );
      l_vendor_contact.vendor_id := rec.vendor_id;
      l_vendor_contact.vendor_site_id := rec.vendor_site_id;
      l_vendor_contact.org_id := rec.org_id;
      l_vendor_contact.person_first_name := rec.person_first_name;
      l_vendor_contact.person_middle_name := rec.person_middle_name;
      l_vendor_contact.person_last_name := rec.person_last_name;
     l_vendor_contact.phone := rec.phone;
      l_vendor_contact.email_address := rec.email_address;
      p_init_msg_list := fnd_api.g_true;
      p_commit := fnd_api.g_false;
      x_return_status := NULL;
      x_msg_count := NULL;
      x_msg_data := NULL;

      IF rec.process_flag = 'I'
      THEN
         fnd_file.put_line (fnd_file.LOG, 'Creating contacts....');
         ap_vendor_pub_pkg.create_vendor_contact
                  (p_api_version             => p_api_version,
                   p_init_msg_list           => p_init_msg_list,
                   p_commit                  => p_commit,
                   x_return_status           => x_return_status,
                   x_msg_count               => x_msg_count,
                   x_msg_data                => x_msg_data,
                   p_vendor_contact_rec      => l_vendor_contact,
                   x_vendor_contact_id       => l_vendor_contact.vendor_contact_id,
                   x_per_party_id            => l_vendor_contact.per_party_id,
                   x_rel_party_id            => l_vendor_contact.relationship_id,
                   x_rel_id                  => l_vendor_contact.rel_party_id,
                   x_org_contact_id          => l_vendor_contact.org_contact_id,
                   x_party_site_id           => l_vendor_contact.party_site_id
                  );
         error_handling (rec.r_id, x_return_status, x_msg_count, x_msg_data);
         fnd_file.put_line (fnd_file.LOG, '*************');
      END IF;
END;



Friday 11 January 2013

Text Attachment content print

Various files are attached in the documents like PO, Requisition, Invoice etc. If an attachment is a text type then  it is possible to print the content of the attachment .

One of the example various PO terms and conditions are added in the PO header or line level. The following script will help print in the report.


/* Formatted on 2013/01/11 23:36 (Formatter Plus v4.8.8) */
DECLARE
   CURSOR cur_file_info (i_hdr_id NUMBER)
   IS
      SELECT DISTINCT seq_num, media_id
                 FROM fnd_attached_docs_form_vl
                WHERE pk1_value = i_hdr_id
                  AND category_description = 'To Supplier'
                  AND datatype_name = 'File'
             ORDER BY seq_num;
BEGIN
   BEGIN
      l_file_content := NULL;

      FOR get_file_content IN cur_file_info (:po_header_id)
      LOOP
         SELECT file_id, file_name
           INTO l_file_id, l_file_name
           FROM fnd_lobs
          WHERE file_content_type = 'text/plain'
            AND file_id = get_file_content.media_id;

         populate_file_content (l_file_id, l_file_content);
      END LOOP;
   END;
END;






PROCEDURE populate_file_content (i_file_id NUMBER, i_file_content OUT VARCHAR2)
IS
   l_blob                   BLOB;
   l_clob                   CLOB             := EMPTY_CLOB ();
   l_src_offset             NUMBER           := 1;
   l_dest_offset            NUMBER           := 1;
   l_blob_csid              INTEGER          := 0;
   v_lang_context           INTEGER          := 0;
   l_warning                NUMBER;
   l_amount                 BINARY_INTEGER;
   l_buffer_size   CONSTANT BINARY_INTEGER   := 32767;
   l_buffer                 VARCHAR2 (32767) := NULL;
   --l_file_content           VARCHAR2 (32767) := NULL;
   l_offset                 NUMBER           := 1;
BEGIN
   l_buffer := NULL;
   DBMS_LOB.createtemporary (l_blob, TRUE);
   DBMS_LOB.createtemporary (l_clob, TRUE);

   SELECT file_data
     INTO l_blob
     FROM fnd_lobs
    WHERE file_id = i_file_id;

   IF DBMS_LOB.getlength (l_blob) > 0
   THEN
      DBMS_LOB.converttoclob (l_clob,
                              l_blob,
                              DBMS_LOB.getlength (l_blob),
                              l_dest_offset,
                              l_src_offset,
                              1,
                              v_lang_context,
                              l_warning
                             );
   END IF;

   l_amount := l_buffer_size;

   WHILE l_amount >= l_buffer_size
   LOOP
      BEGIN
         DBMS_LOB.READ (lob_loc      => l_clob,
                        amount       => l_amount,
                        offset       => l_offset,
                        buffer       => l_buffer
                       );
         l_buffer := REPLACE (l_buffer, CHR (13), '');
         l_offset := l_offset + l_amount;
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;
   END LOOP;

   i_file_content := l_buffer;
EXCEPTION
   WHEN OTHERS
   THEN
      NULL;
END;