Friday, November 13, 2009

Payables


This topic covers how to add attachments through APINV workflow.
1) Download and open workflow from database.
2) Add new attribute in Attribute list
Internal Name : XXSSS_ATTACHMENT
Display Name: XXSSS First Attachment
3) Create new function under Functions tab












Internal Name: XXSSS_APINV_ATT
Display Name: XXSSS Get Attachment
functionName: xxsss_notif_attach_pkg.GetAttachment



4) Attach this function icon in the Sedn Notifications Process












Use the following code for custom function
CREATE OR REPLACE PACKAGE BODY APPS.xxsss_notif_attach_pkg AS
PROCEDURE AttachNotif
(
document_id IN VARCHAR2
,display_type IN VARCHAR2
,document IN OUT BLOB
,document_type IN OUT VARCHAR2
) IS
lob_id NUMBER;
bdoc BLOB;
content_type VARCHAR2(100);
filename VARCHAR2(300);
l_err_msg VARCHAR2(50);
BEGIN
-- apps.set_debug_context('xx_notif_attach_procedure');
lob_id := to_number(document_id);

-- Obtain the BLOB version of the document
SELECT file_name
,file_content_type
,file_data
INTO filename
,content_type
,bdoc
FROM apps.fnd_lobs
WHERE file_id = lob_id;
insert into temp values(4,'lob_id--'to_char(lob_id));
document_type := content_type ';name=' filename;
dbms_lob.copy(document, bdoc, dbms_lob.getlength(bdoc));
insert into temp values(5,'after dbms_lob');
EXCEPTION
WHEN OTHERS THEN
wf_core.CONTEXT('xxsss_notif_attach_pkg'
,'AttachNotif'
,document_id
,display_type);
RAISE;
END AttachNotif;

PROCEDURE GetAttachment (
itemtype IN VARCHAR2
, itemkey IN VARCHAR2
, actid IN NUMBER
, funcmode IN VARCHAR2
, resultout OUT VARCHAR2
) IS

file_id NUMBER;

BEGIN
-- Attachments can be of different types. Also a single invoice can have multiple attachments.
-- I am guessing the user does not want Text and Long Text as an attachment.
-- You will need to add further logic to handle multiple attachments and only non text attachments.

SELECT media_id
INTO file_id
FROM fnd_attached_docs_form_vl
WHERE pk1_value = SUBSTR (itemkey, 1, INSTR (itemkey, '_') - 1)
AND function_name = 'APXINWKB'

wf_engine.setitemattrdocument(
itemtype => itemtype
, itemkey => itemkey
, aname => 'XXSSS_ATTACHMENT'
, documentid => 'PLSQLBLOB:xxsss_notif_attach_pkg.AttachNotif/'to_char(file_id)
);

EXCEPTION
WHEN OTHERS THEN
wf_core.CONTEXT('xxsss_notif_attach_pkg'
,'GetAttachment'
,itemtype
,itemkey);
RAISE;
END GetAttachment ;

end xxsss_notif_attach_pkg;
/