Friday, September 4, 2009

Enforcing Attachments in iExpense/iProcurement

This is one of the cool things that I have done in quite sometime, customization to enforce attachments for Requisitions and Expense Reports. The code does not really check the contents of the attachments, it just checks if the attachments are present or not.

At first, you might think whats the big deal here, you could just use POR_CUSTOM_PKG and AP_WEB_CUST_DFLEX_PKG packages to check if the FND_ATTACHED_DOCUMENTS table has entries for the corresponding requisition or expense report. The issue with using custom hooks is, you do not have control when they would be invoked. If you use the custom hooks to enforce the check, you wont go anywhere.

You could say, why not put the check in the workflow? Return the document to users if there is no attachment. Would it not be better to prevent submission in the first place if the document does not have attachments? You bet it is much cleaner design.

But just checking this table in the custom hooks does not work at all. Why? Simply because the attachments are not pushed to database unless the requisition or expense report is submitted. And you do not want users to submit these without attachments in the first place. This means you need to check in the database as well as middle tier.


How to solve this then?
This needs playing around with Framework code. First you have to figure out the which page is doing the request submission. Once you figure that out, find out the relevant CO (Controller classes). Then you have to get handle to the FND Attachments VO, and check if the VO has any records. If you do not find any records in here, then check if the attachments are there in database. Doing it this way its going to be a foolproof solution.

The real challenge is to figure out right attachments VO. It took me quite sometime to figure out which VO it was really. Its fun, I can tell you.

1 comment:

M V Rajesh said...

Yes you are corecct, but there is a problem here even if you get handle of FNDAttachmentsVO. The problem is , once an attachment is attached the VO returns correctly the no.of rows, but if you go to attachments and delete the attachment, it still shows the row as 1. Just chk it out.