Attachments in Oracle Applications
Attachments in Oracle Applications
Other specifications in this table include: datatype (DATATYPE_ID, where 1=short text,2=long text, 3=image, 4=OLE object), image
type, and storage type (STORAGE_TYPE, where 1=stored in the database, 2=stored in the file system).
The document can be referenced by many application entities and changed only in the define document form (USAGE_TYPE=S); it
can be used as a fill-in-the-blanks document, where each time you use a template, you make a copy of it (USAGE_TYPE=T); or it
can be used only one time (USAGE_TYPE=O).Images and OLE Objects cannot be used as templates.
FND_ATTACHED_DOCUMENTS:
FND_ATTACHED_DOCUMENTS stores information relating a document to an application entity. For example, a record may link a
document to a sales order or an item. Each row contains foreign keys to FND_DOCUMENTS and FND_DOCUMENT_ENTITIES.
There is also a flag to indicate whether or not an attachment was created automatically.
FND_DOCUMENTS_TL:
FND_DOCUMENTS_TL stores translated information about the documents in FND_DOCUMENTS. Each row includes the
document identifier, the language the row is translated to, the description of the document, the file in which the image is stored, and
an identifier (MEDIA_ID) of the sub-table in which the document is saved (FND_DOCUMENTS_SHORT_TEXT,
FND_DOCUMENTS_LONG_TEXT, or FND_DOCUMENTS_LONG_RAW).
FND_DOCUMENT_DATATYPES:
FND_DOCUMENT_DATATYPES stores the document datatypes that are supported. Initial values are: short text, long text, image,
and OLE Object (DATATYPE_ID=1, 2, 3, or 4). Customers can add datatypes to handle documents stored outside of Oracle and
use non-native Forms applications to view/edit their documents. The table uses a duplicate record model for handling multi-lingual
needs. That is, for each category there will be one record with the same CATEGORY_ID and CATEGORY_NAME for each
language.
FND_DOCUMENT_CATEGORIES:
FND_DOCUMENT_CATEGORIES stores information about the categories in which documents are classified. For example,
documents may be considered Bill of Material Comments, WIP Job Comments, etc. Document categories are used to provide a
measure of security on documents. Each form that enables the attachment feature lists which categories of documents can be
viewed in the form. This table uses a duplicate record model for handling multi-lingual needs.
FND_DOCUMENTS_LONG_TEXT:
FND_DOCUMENTS_LONG_TEXT stores information about long text documents.
FND_DOCUMENTS_SHORT_TEXT:
FND_DOCUMENTS_SHORT_TEXT stores information about short text documents.
FND_DOCUMENTS_LONG_RAW:
FND_DOCUMENTS_LONG_RAW stores images and OLE Objects, such as Word Documents and Excel spreadsheets, in the
database.
FND_DOCUMENT_ENTITIES:
FND_DOCUMENT_ENTITIES lists each entity to which attachments can be linked. For example, attachments can be linked to
Items, Sales Orders, etc. Since the table uses a duplicate record model for handling multi-lingual needs, for each document entity
there will be one record with the same DOCUMENT_ENTITY_ID and DATA_OBJECT_CODE for each language.
Queries:
1] To find all Long Text attachments:
SELECT
FROM
WHERE
SELECT
FROM
WHERE
fdt_f.file_name media_data_text
from
fnd_attached_documents fad_f
fnd_documents fd_f
fnd_documents_tl fdt_f
fnd_document_categories_tl fdct_f
where
1 = 1
and
fad_f.document_id = fd_f.document_id
and
fad_f.document_id = fdt_f.document_id
and
fdct_f.category_id = fd_f.category_id
and
and
fd_f.datatype_id = 5
and
fad_f.entity_name = 'AP_INVOICES'
and
fad_f.pk1_value = '63227';
fdlt_f.media_id
fdlt_f.long_text media_data_text
from
fnd_attached_documents fad_f
fnd_documents fd_f
fnd_documents_tl fdt_f
fnd_document_categories_tl fdct_f
fnd_documents_long_text fdlt_f
where
1 = 1
and
fad_f.document_id = fd_f.document_id
and
fad_f.document_id = fdt_f.document_id
and
fdct_f.category_id = fd_f.category_id
and
-- and
media_id
and
and
fad_f.entity_name = 'AP_INVOICES'
and
fad_f.pk1_value = '63227';
fdst_f.media_id
fdst_f.short_text media_data_text
media_id
from
fnd_attached_documents fad_f
fnd_documents fd_f
fnd_documents_tl fdt_f
fnd_document_categories_tl fdct_f
fnd_documents_short_text fdst_f
where
1 = 1
and
fad_f.document_id = fd_f.document_id
and
fad_f.document_id = fdt_f.document_id
and
fdct_f.category_id = fd_f.category_id
and
-- and
and
and
fad_f.entity_name = 'AP_INVOICES'
and
fad_f.pk1_value = '63227';
fl_l.file_id
media_id
fl_l.file_data
media_data_blob
from
fnd_attached_documents fad_l
fnd_documents fd_l
fnd_documents_tl fdt_l
fnd_document_categories_tl fdct_l
fnd_lobs fl_l
where
1 = 1
and
fad_l.document_id = fd_l.document_id
and
fad_l.document_id = fdt_l.document_id
and
fdct_l.category_id = fd_l.category_id
and
fad_l.entity_name = 'AP_INVOICES'
and
and
fad_l.pk1_value = '63227';
Update: Added extra line to file query for R12. Update: In case anyone needs to delete any
attachments here's an example (thanks to Mark L):
declare
l_entity_name varchar2(20):= 'PO_LINES';
begin
--fnd_global.apps_initialize(0,20420,1); -- SYSADMIN System Administrator
fnd_attached_documents2_pkg.delete_attachments
( X_entity_name
=> l_entity_name
, X_pk1_value
=> l_pk1_value
, X_delete_document_flag
=> l_delete_document_flag
);
end;
/
commit;
/**
* Script Description :- Single Insert Script to Attachments *
* Author :- Venu Sreeramoju *
* Date :- 22 October 2011 *
* *
* *
* Pre-Requirements *
* *
* 1.Create a Custom Directory and Grant Permissions *
* 2.Place the Files in this Directory as Below *
* *
* CREATE OR REPLACE DIRECTORY Apps AS '/usr/tmp/venu'; *
* GRANT READ ON DIRECTORY Apps TO PUBLIC; *
* *
**/
DECLARE
l_rowid
ROWID;
l_attached_document_id NUMBER;
l_document_id
NUMBER;
l_media_id
NUMBER;
l_file_id
NUMBER;
l_category_id
NUMBER := 1;
nvl(MAX(seq_num), 0) + 10
l_seq_num
fnd_attached_documents
pk1_value = l_pk1_value
entity_name = 'MTL_SYSTEM_ITEMS';
program_name,
program_tag,
file_data,
LANGUAGE,
oracle_charset,
file_format)
VALUES
(l_media_id,
l_filename,
'application/pdf',
SYSDATE,
NULL,
'FNDATTCH',
NULL,
empty_blob(),
'US',
'UTF8',
'BINARY')
RETURNING file_data INTO x_blob;
DBMS_LOB.OPEN(l_bfile, DBMS_LOB.lob_readonly);
DBMS_LOB.OPEN(x_blob, DBMS_LOB.lob_readwrite);
DBMS_LOB.loadfromfile(x_blob, l_bfile, blob_length);
DBMS_LOB.CLOSE(x_blob);
DBMS_LOB.CLOSE(l_bfile);
COMMIT;
DBMS_OUTPUT.put_line('File Successfully Inserted into Table as BLOB');
DBMS_LOB.CREATETEMPORARY(x_blob, TRUE);
COMMIT;
IF DBMS_LOB.FILEEXISTS(l_bfile) = 1
THEN
dbms_output.put_line(' File Exists!');
ELSE
dbms_output.put_line('Not Exists!');
END IF;
fnd_documents_pkg.insert_row(X_ROWID
=> l_rowid,
X_DOCUMENT_ID
=> l_document_id,
X_CREATION_DATE
=> SYSDATE,
X_CREATED_BY
=> 1008030,
X_LAST_UPDATE_DATE => SYSDATE,
X_LAST_UPDATED_BY
=> 1008030,
X_LAST_UPDATE_LOGIN => 1008030,
X_DATATYPE_ID
=> 6 FILE,
X_CATEGORY_ID
=> l_category_id,
X_SECURITY_TYPE
=> 2,
X_PUBLISH_FLAG
=> 'Y',
X_USAGE_TYPE
=> 'O',
X_LANGUAGE
=> 'US',
X_DESCRIPTION
=> l_description,
X_FILE_NAME
=> l_filename,
X_MEDIA_ID
=> l_media_id);
COMMIT;
--dbms_output.put_line ('document id is l_document_id '||l_document_id);
fnd_documents_pkg.insert_tl_row(X_DOCUMENT_ID
=> l_document_id,
X_CREATION_DATE
=> SYSDATE,
X_CREATED_BY
=> 1008030,
X_LAST_UPDATE_DATE => SYSDATE,
X_LAST_UPDATED_BY
=> 1008030,
X_LAST_UPDATE_LOGIN => 1008030,
X_LANGUAGE
=> 'US',
X_DESCRIPTION
=> l_description,
X_FILE_NAME
=> l_filename,
X_MEDIA_ID
=> l_media_id);
COMMIT;
--dbms_output.put_line ('attachment_document id is l_attached_document_id '||
l_attached_document_id);
--l_document_id :=l_document_id-1;
fnd_attached_documents_pkg.insert_row(X_ROWID
=> l_rowid,
X_ATTACHED_DOCUMENT_ID
=>
l_attached_document_id,
X_DOCUMENT_ID
=> l_document_id,
X_CREATION_DATE
=> SYSDATE,
X_CREATED_BY
=> 1008030,
X_LAST_UPDATE_DATE
=> SYSDATE,
X_LAST_UPDATED_BY
=> 1008030,
X_LAST_UPDATE_LOGIN
=> 1008030,
X_SEQ_NUM
=> l_seq_num,
X_ENTITY_NAME
=>
'MTL_SYSTEM_ITEMS',
X_COLUMN1
=> NULL,
X_PK1_VALUE
=> l_pk1_value,
X_PK2_VALUE
=> 1225112164
carbody_d11991
car_433,
X_PK3_VALUE
=> NULL,
X_PK4_VALUE
=> NULL,
X_PK5_VALUE
=> NULL,
X_AUTOMATICALLY_ADDED_FLAG => 'N',
X_DATATYPE_ID
=> 6,
X_CATEGORY_ID
=> l_category_id,
X_SECURITY_TYPE
=> 2,
X_PUBLISH_FLAG
=> 'Y',
X_LANGUAGE
=> 'US',
X_DESCRIPTION
=> l_description,
X_FILE_NAME
=> l_filename,
X_MEDIA_ID
=> l_media_id);
COMMIT;
dbms_output.put_line('attachment_document id is l_attached_document_id ' ||
l_attached_document_id);
dbms_output.put_line('document id is l_document_id ' || l_document_id);
dbms_output.put_line(' l_media_id ' || l_media_id);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Failed ' || SQLERRM);
COMMIT;
END;
--------------------------select * from all_directories;
http://oracleappsengineering.blogspot.ca/2010/04/attachments-api-fnddocumentspkg.html
http://oraclemaniac.com/2012/01/07/attach-concurrent-program-output-to-the-apps-transaction/
http://garethroberts.blogspot.ca/2007/08/document-attachments-private-stuff.html
http://imdjkoch.wordpress.com/2010/09/02/attachment-in-oracle-application/