DECLARE
p_pk1_value fnd_attached_documents.pk1_value%TYPE := '259330';
P_ORG_ID NUMBER := 204;
p_short_text varchar2(4000) := 'Successfully Deleted the Line' ;
l_rowid ROWID;
l_attached_document_id NUMBER;
l_document_id NUMBER;
l_media_id NUMBER;
l_category_id NUMBER;
l_pk1_value fnd_attached_documents.pk1_value%TYPE;
l_seq_num NUMBER;
l_fnd_user_id NUMBER := fnd_profile.VALUE('USER_ID');
l_short_datatype_id NUMBER;
l_entity_name VARCHAR2(100) := 'OE_ORDER_HEADERS';
l_category_name VARCHAR2(100) := 'Short Text';--'Sales Order Lines Deletion';
-- p_org_id number := fnd_profile.value(‘org_id’);
BEGIN
l_pk1_value := p_pk1_value;
dbms_output.put_line( 'l_pk1_value :-'||l_pk1_value);
SELECT fnd_documents_s.NEXTVAL
INTO l_document_id
FROM DUAL;
DBMS_OUTPUT.PUT_LINE( 'l_document_id :-'||l_document_id);
SELECT fnd_attached_documents_s.NEXTVAL
INTO l_attached_document_id
FROM DUAL;
DBMS_OUTPUT.PUT_LINE( 'l_attached_document_id :-'||l_attached_document_id);
SELECT NVL (MAX (seq_num), 0) + 10
INTO l_seq_num
FROM fnd_attached_documents
WHERE pk1_value = l_pk1_value
AND entity_name = l_entity_name;
DBMS_OUTPUT.PUT_LINE( 'l_seq_num :-'||l_seq_num);
-- Get Data type id for Short Text types of attachments
SELECT datatype_id
INTO l_short_datatype_id
FROM apps.fnd_document_datatypes
WHERE NAME = 'SHORT_TEXT';
-- Select Category id for Attachments
DBMS_OUTPUT.PUT_LINE( 'l_short_datatype_id :-'||l_short_datatype_id);
SELECT category_id
INTO l_category_id
FROM apps.fnd_document_categories_vl
WHERE USER_NAME = l_category_name;
-- This package allows user to share file across multiple orgs or restrict to single org
DBMS_OUTPUT.PUT_LINE( 'l_category_id :-'||l_category_id);
fnd_documents_pkg.insert_row
(x_rowid => l_rowid,
x_document_id => l_document_id,
x_creation_date => SYSDATE,
x_created_by => l_fnd_user_id,-- fnd_profile.value('USER_ID')
x_last_update_date => SYSDATE,
x_last_updated_by => l_fnd_user_id,-- fnd_profile.value('USER_ID')
x_last_update_login => fnd_profile.VALUE('LOGIN_ID'),
x_datatype_id => l_short_datatype_id, -- SHORT TEXT
x_security_id => Null,--p_org_id,
x_publish_flag => 'Y', --This flag allow the file to share across multiple organization
x_category_id => l_category_id,
x_security_type => 4,--1 tBC
x_usage_type => 'O',
x_language => 'US',
x_media_id => l_media_id
);
DBMS_OUTPUT.PUT_LINE( 'l_media_id :-'||l_media_id);
-- Insert a new record into the table containing the sort text
INSERT INTO FND_DOCUMENTS_SHORT_TEXT
(media_id, short_text
)
VALUES (l_media_id, p_short_text
);
DBMS_OUTPUT.PUT_LINE( 'p_short_text :-'||p_short_text);
fnd_documents_pkg.insert_tl_row
(x_document_id => l_document_id,
x_creation_date => SYSDATE,
x_created_by => l_fnd_user_id,--fnd_profile.VALUE('USER_ID'),
x_last_update_date => SYSDATE,
x_last_updated_by => l_fnd_user_id,--fnd_profile.VALUE('USER_ID'),
x_last_update_login => fnd_profile.VALUE('LOGIN_ID'),
x_language => 'US'
);
DBMS_OUTPUT.PUT_LINE( 'Success :- 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 => l_fnd_user_id,--fnd_profile.VALUE('USER_ID'),
x_last_update_date => SYSDATE,
x_last_updated_by => l_fnd_user_id,--fnd_profile.VALUE('USER_ID'),
x_last_update_login => fnd_profile.VALUE('LOGIN_ID'),
x_seq_num => l_seq_num,
x_entity_name => l_entity_name,
x_column1 => NULL,
x_pk1_value => l_pk1_value,
x_pk2_value => NULL,
x_pk3_value => NULL,
x_pk4_value => NULL,
x_pk5_value => NULL,
x_automatically_added_flag => 'N',
x_datatype_id => l_short_datatype_id,
x_category_id => l_category_id,
x_security_type => 4,
x_security_id => p_org_id,
x_publish_flag => 'Y',
x_language => 'US',
x_media_id => l_media_id
);
DBMS_OUTPUT.PUT_LINE( 'Success :- 2');
commit;
Exception
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE( 'Error from Above :'||SQLERRM);
END;