Monday, October 31, 2016

How to add Attachments (pdf, word, excel, img etc) in Workflow Notifications.



Lets suppose we want to send the "Terms & Conditions" pdf file to the approver that is attached at PO_HEADERS block of Quotations. You need to do the following:

1 - Create a Document type attribute with Source as Send in the message of approval notification as following






Value field must be like that
 
plsqlblob:package_name.procedure_name/&document_id
 
In this case the document is a binary file so plsqlblob specifier would be used and  document_id should be the value of Po_headers_all.header_id which is stored in P_HEADER_ID attribute hence the Value field is:
 
=>  plsqlblob:cust_qoutations_wf.get_attachment/&P_HEADER_ID 
 
Click Apply button after entering all the detail. 
 
Save the workflow definition in the DB. 
  
 Next you need to create the package procedure as the below one in the apps schema which will be called by the workflow engine to get the attachment.
 
 
Create or Replace PACKAGE BODY CUST_QOUTATIONS_WF AS
--
 
  PROCEDURE get_attachment(document_id   in varchar2,
                                                    display_type  in varchar2,
                                                    document      in out blob,
                                                    document_type in out NOCOPY varchar2)
  
     is
  
      lv_file_name           VARCHAR2 (100) := NULL;
      lv_file_content_type   VARCHAR2 (100) := NULL;
      lv_doc_in            BLOB;
      lv_document_id po_headers_all.PO_HEADER_ID%TYPE;
      lv_length Integer;
  begin
    lv_document_id := document_id;
 
      select fl.file_name, fl.file_content_type, fl.file_data
       INTO lv_file_name, lv_file_content_type, lv_doc_in
      from APPLSYS.FND_ATTACHED_DOCUMENTS fad,
           APPLSYS.FND_DOCUMENTS fd ,
           APPLSYS.FND_LOBS fl
      where fad.ENTITY_NAME = 'PO_HEADERS'
        and fad.DOCUMENT_ID = fd.DOCUMENT_ID
        and fd.MEDIA_ID = fl.FILE_ID
        and fad.PK1_VALUE = lv_document_id ;
 
      document_type := lv_file_content_type || ';name=' || lv_file_name;

     lv_length := DBMS_LOB.getlength(lv_doc_in);
     
       DBMS_LOB.COPY (dest_lob => document,
                                           src_lob  => lv_doc_in,
                                           amount   => lv_length);
    commit;
  
  exception
    when others then
      wf_core.context('CUST_QOUTATIONS_WF',
                      'get_attachment',
                       document_id);
    raise;
   
 end;
 
 --
 
end CUST_QOUTATIONS_WF;
 
 
 
Hope that will help.

Thanks
 
 
 
 



 

No comments:

Post a Comment