This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License.








Friday, September 01, 2006

Blob as Oracle Workflow Attachment

Please find a 4 step solution to send Binary Document Attachments with Oracle Workflows Notifications. Using this technique you can generate email notifications with attachments for MsWord, or PDF or any other binary files.

Oracle has made sending binary documents as attachments with notifications a piece of cake. In the example below, I am assuming only one attachment per notification. However, you can create as many Attachment attributes you wish, and also can programmatically control how many attachments are sent per transactions. Anyway, below are four simple steps for sending Workflow Notifications with Attachments.


Step 1

As in the picture below, workflow Message “XX_G4G Notification With Attachment” is defined. This message will be referenced by the Notification that sends either MsWord or PDF or any other binary attachment as email.




Step 2.

Define an attribute to the message defined in Step 1. This is shown in the picture below. Following must be noted:-
Type: Document
Source: Send
Frame Target: New Window
Attach Content: Yes.


If you had dragged the Attribute from Workflow level into this message, then default sub-section will be populated automatically.



Step 3.

After executing the wf_engine.createprocess and before executing wf_engine.startprocess, we need to set a value for the attribute defined in Step 2. This can be done by calling wf_engine.setitemattrdocument as below
wf_engine.setitemattrdocument
(itemtype=>'XG4GWFIT'
, itemkey=>'XG4GWFIT' || l_item_key
, aname=>'XX_G4G_ATTACHMENT1'
, documentid =>'PLSQLBLOB:xx_g4g_package.xx_notif_attach_procedure/' || to_char(l_file_id));

Please note the manner in which parameter documented is assigned. The syntax is PLSQLBLOB:./ . In my example, I am capturing the file_id from fnd_lobs. In your case this ID will be derived depending upon whether you are looking for PO Attachment or say an attachment to Oracle Sales Order or a Resume in iRecruitment or some course notes in oracle Learning Management.



Step 4.

Handle the execution of the procedure, in this case xx_notif_attach_procedure

PROCEDURE xx_notif_attach_procedure
(
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);
BEGIN
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 fnd_lobs
WHERE file_id = lob_id;
document_type := content_type || ';name=' || filename;
dbms_lob.copy(document, bdoc, dbms_lob.getlength(bdoc));
EXCEPTION
WHEN OTHERS THEN
debug('ERROR ^^^^0018 ' || SQLERRM);
wf_core.CONTEXT('xx_g4g_package'
,'xx_notif_attach_procedure'
,document_id
,display_type);
RAISE;
END xx_notif_attach_procedure;


Please note the following:-
Note 1. In step 3, the value of Unique File id that is passed in after / gets translated into document_id in step 4. This translation occurs within the workflow engine, when it splits the pl/sql name from parameter.
Note 2. Proecdure xx_notif_attach_procedure must be defined in the package specification too.
Note 3. This procedure has an out parameter “document IN OUT BLOB”
Note 4. The value from the Oracle Blob column is fetched into blob variable bdoc from fnd_lobs.
Note 5. Next you can use dbms_lob.copy to copy the value from blob variable into out parameter for notification.

When I implemented this the very first time, I could hardly believe it to be as simple as this, to implement BLOB attachments in Oracle Workflow Notifications.


Thanks,
Anil Passi

Comments on ""

 

Anonymous Anonymous said ... (9:12 AM) : 

Is it necessary to output document_type and document?
Or i need only document in generate procedure?

 

Anonymous Anonymous said ... (9:15 AM) : 

Is it necessary to output document_type and document?
Or i need only document in generate procedure?

 

Anonymous Anonymous said ... (5:52 PM) : 

We have tried this and for BLOBs under 300k and it seems to work fine. Have you been successful with this for Large BLOBS? We are getting the attachments corrupted when they reach the recipients’ email. The size of the attached documents are around 500-600k.

 

Blogger Anil Passi said ... (7:45 PM) : 

Hi Anonymous

We never faced any issues with sizing.

You can safely raise an SR

Thanks,
Anil Passi

 

Anonymous Anonymous said ... (12:08 PM) : 

Hi Anil,

Thanks...Your document proved to be very useful for me when I was developing my first custom workflow. :)

I am facing some roadblocks however...
1) The workflow notification that I created is supposed to contain 2 attachments. The first attachment can be viewed easily while opening the notification from the worklist but the second attachment (which is the same as the first attachment, only file id is different) cannot be viewed. On clicking the attachment icon, a blank page loads. Should multiple attachments be handled differently? I have created 2 attachment attributes.

2) Also, in the notification, the attachment name is seen as the display name of the attachment attribute. I need to get the actual file name displayed somehow instead. Any suggestions on how to do so?

Thanks a lot in advance.

Regards,
RLD

 

Anonymous Anonymous said ... (3:33 PM) : 

Anil,

Thanks for this article. I have followed all the instructions and I get links to open attachment. EVen though it recognize the filename and filetype, its not showing me any content of the file.

I have verified that BLOB is returing right content when I use it through SQL.

Thanks,
Mahesh

 

Blogger coolvizith said ... (9:14 AM) : 

Hi Anil,

You are truly genius, It worked like a magic,

Thanks a ton,

But one small doubt, Is there any way to purge fnd_lobs

Best Regards,
Vizith

 

Blogger coolvizith said ... (9:15 AM) : 

Hi Anil,

You are truly genius, It worked like a magic,

Thanks a ton,

But one small doubt, Is there any way to purge fnd_lobs

Best Regards,
Vizith

 

post a comment