Thursday, January 29, 2009

Printing Word doc FND attachments

We recently came across an unique requirement of printing the Word document attachments along with a report. I googled and metalinked. But found no direct solution and there were few open Enhancement Requests open with Oracle. We finally found a way. The idea is very simple. Get the attachments BLOB stored in database to apps server using JDBC and print the file using soffice. But lotsa work must be done and most of them need an APPS DBA's help. This article outlines the steps but not in detail. You should spend some time based on your apps configuration to get it work.

Technical Overview of FND attachments.

All file attachments are stored in FND_LOBS table in file_data column. You can link this back to your attachment entity using the following query.

SELECT fl.file_data,
fdt.media_id,
fad.entity_name,
fdt.description
FROM fnd_attached_documents fad,
fnd_documents_tl fdt,
fnd_lobs fl
WHERE fad.document_id = fdt.document_id
AND fl.file_id = fdt.media_id
AND fdt.language = userenv('Lang')
AND fad.entity_name = 'MTL_SYSTEM_ITEMS'
AND fad.pk1_value = 183
AND fad.pk2_value = 164217



Here we are getting the attachment details of Discrete Item Master (Entity_Name: MTL_SYSTEM_ITEMS) and primary key values PK1_VALUE(Organization_ID) and PK2_VALUE (Inventory_Item_id).

For your entity you can get the details by navigating to Responsibility: Application Developer and Menu Navigaton: Attachments > Document Entity and Attachments > Attachment Functions.






Steps to print the attachments

Step 1: Java program to bring attachment BLOB to apps tier. Link.
This program gets media id and brings the BLOB from fnd_lob to apps tier.

Parameters : 1:User name 2:Password 3:Host 4:Port 5:SID 6:MediaId 7:FileSuffix

Step 2: Download Open Office and configure it in apps tier. I used my Apps DBA's help for it and it is a linux expert job.

Vaguely we have to do the following.
a.Install open office on the server
b.Log in as the oraowner, start a X session and launch open office writer
c.From root run the following: (This will need to be run after reboot or added as a service)
$ unset DISPLAY
$ soffice –headless –accept="socket,host=127.0.0.1,port=8100;urp;" –nofirststarwizard


Step 3: Create a simple shell script to use Java program in Step 1 and Open Office in Step 2 to print the file.

#!/bin/ksh
# $Header: XXAttachmentPrint.ksh$
#
# Purpose:
# Copy a file from the db to a temp location and print it.
#
# $5 MediaId
# $6 FileName
# $7 PrinterName
#
# Set Application Environment Variables
export PATH=${PATH}:/usr/local/bin
export XXENVPREF=`echo ${TWO_TASK}|awk ' { print tolower($1) } '`

# intialize the apps context in linux. You must replace this with your logic for executing APPSORA.env from $APPL_TOP
. XXsetenv${XXENVPREF}.ksh
. XXSetAppsEnv.ksh


export MEDIAID=${5}
echo "MediaId=" ${MEDIAID}
export FILENAME=${6}
echo "FileName=" ${FILENAME}
export PRINTERNAME=${7}
echo "PrinterName=" ${PRINTERNAME}

# Change Directory to temp location
cd ${COMMON_TOP}/temp

# Execute the java code to extract file. You can read db user name, passwd host etc from concurrent program params 1-4 or read it from another
# file/ exported variables in instance.
java tempel.oracle.apps.xxtmg.crm.AttachmentReader apps `cat ~/APPSpswd${XXENVPREF}.txt` ${XXDBHOST} ${XXDBPORT} ${XXENV} ${MEDIAID} ${FILENAME}.doc

# Open Office print command
soffice -headless -pt ${PRINTERNAME} ${FILENAME}.doc

# Clean up extracted document
rm ${FILENAME}.doc

#
# End of File




Step 4: Seed the above shell script as a concurrent program in APPS.

Application Developer > Concurrent > Programs/Executable


Execution file name should be same as the script name in Step 3.



Step 5
: Write a simple PLSQL program which based on entity name and PK value launches the Step 4 program by passing parameters for media id, printer and file name.
PROCEDURE print_mtl_attachments(p_organization_id IN NUMBER,
p_inventory_item_id IN NUMBER) IS

CURSOR c IS
SELECT fdt.media_id
FROM fnd_attached_documents fad,
fnd_documents_tl fdt,
fnd_lobs fl
HERE fad.document_id = fdt.document_id
AND fl.file_id = fdt.media_id
AND fdt.language = userenv('Lang')
AND fad.entity_name = 'MTL_SYSTEM_ITEMS'
AND fad.pk1_value = p_organization_id
AND fad.pk2_value = p_inventory_item_id;

l_request_id NUMBER;
BEGIN

FOR c_rec IN c LOOP
x_request_id :=
fnd_request.submit_request (<app short name>,
<prog short name from step 4>,
<some desc>,
TO_CHAR (SYSDATE, 'YYYY/MM/DD HH24:MI:SS'),
FALSE,
c_rec.media_id,
'F' || c_rec._media_id || '-' || to_char(SYSDATE,'MMDDYYYYHH24MISS', -- unique file name,
<printer name>
);
END LOOP;

END print_mtl_attachments;


Step 6: Seed another concurrent program for the PLSQL in step 5.

Step 7: Add concurrent program in Step 6 to a request set containing your report.

Friday, January 2, 2009

When To Fuse

Oracle, by announcing Application Unlimited are suggesting customers to take an evolutionary path to Oracle Fusion applications. In layman terms, they are asking Customers to take their own time to move to Fusion Apps. Which certainly has failed to enthuse most of the customers and most of them will hesitate to adopt the Apps in the foreseeable future. There is a hope that Larry Ellison might pull a Steve Jobs in terms of time to market and convincing customers to embrace the new technology. But ERP is not a fancy utility device and they might even miss the oppurtunity. As far as I (Oracle Apps Technical Consultant), am concerned, the big buck question is when is the right time to start learning Fusion? Or with my current skill sets (read Apps 11i and OA Framework) how fast I will get out dated?

One thing is for certain. Fusion is for real. I met few of my old colleagues at Oracle who are currently part of Fusion Apps development. And based on it, insider information or rumor or whatever you want to call, but certianly from reliable resources
  • Coding is almost over and it might hit the market (may be to privileged few) around October 2009.
  • It is toned down version with minimum features.
  • It is developed almost from scratch. And not using the database design of EBS 11i or 12.
  • Lots of RAD and less coding.
  • They faced huge number of issues with Fusion Tech stack and believes it is still evolving and might take some releases to stabilize.
  • Entirey different from OAF. There are some similarities.
  • Dont worry about learning Fusion tecnology now.

Oracle is also recommending most Customers/Oracle Apps Consulting Organizations to start learning Fustion middleware and related technologies like SOA, BPEL, BIEE etc. And also promises that future releases of EBS will be using these techologies.

I will try to make a very silly guess how long OAF will last and when we should start embracing the Fusion technologies?

Oracle EBS Timeline

1987 - Oracle started its application division
1993 - First client server application release
1997 - Oracle announces native Java support and promises new set of RAD tools in Java. Genesis of Jdeveloper.
1998 - Oracle announces EBS 10.7 NCA
1999 - Releases Jdeveloper 2.0
EBS - Releases 11.0.3
2000 - First release of EBS 11i (11i1 and 11i2)
First release of Oracle 9i Application server
2001 - Release 11i3, 11i4 and 11i5
Release of Oracle 9i JDeveloper
2002 - Release of 11i6, 11i7 and 11i8.
Used JTF-the mother of OAF*
2003 - Release of 11i9
Started using OAF in its products.*
2004 - Release of 11i10
Maybe first stable and ironically last release of OAF as after 11.5.10 Oracle internally stopped providing enhancements or additions to OAF.*
2005 - Announces Project Fusion after acquiring host of companies.
2007 - Release of 12
2008 - Release of Fusion middle ware
Announcement of Application Unlimited and Evolutionary path to Fusion.


Timeline reference:

http://www.oracle.com/oraclemagazine/20/o20timeline.html

http://www.oracle.com/support/library/brochure/lifetime-support-applications.pdf

http://apps2fusion.com/apps/oa-framework/197-brief-history-of-oa-framework-and-future

* No references available.


Some observations based on the above timelines.
- It took seven years (97-04) for OAF or to be precise web based ERP application technology stack to become stable internally. OAF started percolating to outside consultancy world only after 11i10.
- It took six years and seven major releases for Oracle to release a relatively stable first application (11i7).

And my silly guess.

2009 - First cut privileged release of Fusion Apps.
2010 - EBS new release with more features from Fusion middleware.
2011 - First market release of Fusion Apps. Stable Fusion middleware.
2012 - Migration path to EBS to Fusion Apps clear.
2013/14 - Few more release of EBS slowly migrating towards Fusion and few more Fusion Apps releases.
2015 - No more new EBS releases and customers slowly start embracing Fusion Apps releases.


So,

- We got another two years for first stable release of Fusion Apps
- We got three years before EBS start looking like Fusion Apps.
- We got a good six year before Oracle might stop making EBS releases or OAF is completely out of the scene.

And a big question mark looms around the success of Fusion Middleware.

I don't want to make any conclusions and leave the readers to make chocies.