Hi all,
How do I create a new document containing a empty file with a RMB?
More about the background here
Hi all,
How do I create a new document containing a empty file with a RMB?
More about the background here
Hope below script will do the thing or at least clear steps involved.
My intention was to create document until checkin the file but hopefully it can be use for your requirement to create empty document.
-- Created on 1/24/2020 by DSJ
declare
-- Local variables here
file_data_ BLOB;
title_attr_ VARCHAR2(32000);
attr_ VARCHAR2(32000);
objid_ VARCHAR2(2000);
objversion_ VARCHAR2(2000);
action_ VARCHAR2(2000);
operation_ VARCHAR2(2000);
info_ VARCHAR2(32000);
title_ DOC_ISSUE_REFERENCE.title%TYPE := 'Drawing for ';
doc_class_ DOC_ISSUE_REFERENCE.doc_class%TYPE := 'DRAWING';
doc_format_ DOC_ISSUE_REFERENCE.format_size%TYPE := NULL;
doc_no_ DOC_ISSUE_REFERENCE.doc_no%TYPE := NULL;
doc_sheet_ DOC_ISSUE_REFERENCE.doc_sheet%TYPE;
doc_rev_ DOC_ISSUE_REFERENCE.doc_rev%TYPE;
document_type_ DOC_ISSUE_REFERENCE.doc_type%TYPE;
file_type_ DOC_ISSUE_REFERENCE.file_type%TYPE := 'ACROBAT';
dummy_out_ EDM_FILE_TAB.local_path%TYPE;
user_file_name_ EDM_FILE_TAB.user_file_name%TYPE;
user_created_ DOC_TITLE.user_created%TYPE := FND_SESSION_API.Get_Fnd_User;
result_key_ PDF_ARCHIVE_TAB.RESULT_KEY%TYPE;
part_no_ VARCHAR2(100);
created_from_ VARCHAR2(4000);
error_text_ VARCHAR2(4000) := '';
project_no_ VARCHAR2(100);
contract_ VARCHAR2(100);
begin
contract_ := '1';
part_no_ := '0001';
title_ := title_ || part_no_;
--Create Doc Title Rev
doc_rev_:= Doc_Class_Default_API.Get_Default_Value_( doc_class_ ,'DocTitle','DOC_REV');
doc_sheet_:= Doc_Class_Default_API.Get_Default_Value_( doc_class_ ,'DocTitle','DOC_SHEET');
Client_SYS.Clear_Attr(attr_);
Client_SYS.Clear_Attr(title_attr_);
Client_SYS.Add_To_Attr('DOC_CLASS', doc_class_, attr_);
Client_SYS.Add_To_Attr('DOC_SHEET', doc_sheet_, attr_);
Client_SYS.Add_To_Attr('DOC_REV', doc_rev_, attr_);
Client_SYS.Add_To_Attr('TITLE', title_, title_attr_);
Client_SYS.Add_To_Attr('STRUCTURE', 0, title_attr_);
Doc_Issue_API.Create_Title_And_Rev__ ( info_ , attr_ , title_attr_ );
doc_no_ := Client_SYS.Get_Item_Value('DOC_NO', attr_); --get generated DOC_NO
document_type_ := 'ORIGINAL';
--Create file reference in IFS Docman
Edm_File_API.Create_File_Reference(dummy_out_, doc_class_, doc_no_, doc_sheet_, doc_rev_, document_type_, file_type_, NULL, 1, user_file_name_);
--Set file state in IFS Docman
action_ := 'CheckOut';
EDM_FILE_API.Set_File_State( doc_class_, doc_no_, doc_sheet_, doc_rev_, document_type_, action_, NULL );
--Start check in of local file in IFS Docman/
action_ := 'StartCheckIn';
EDM_FILE_API.Set_File_State( doc_class_, doc_no_, doc_sheet_, doc_rev_, document_type_, action_, user_file_name_ );
--Finish check in
action_ := 'FinishCheckIn';
EDM_FILE_API.Set_File_State( doc_class_, doc_no_, doc_sheet_, doc_rev_, document_type_, action_, user_file_name_ );
--Add View copy
document_type_ := 'VIEW';
EDM_FILE_API.Create_File_Reference(dummy_out_, doc_class_, doc_no_, doc_sheet_, doc_rev_, document_type_, file_type_, NULL, 0, user_file_name_);
EDM_FILE_API.Set_File_State( doc_class_, doc_no_, doc_sheet_, doc_rev_, document_type_, action_, user_file_name_ );
--Create file record in EDM
Client_SYS.Clear_Attr(attr_);
Client_SYS.Add_To_Attr('DOC_CLASS', doc_class_, attr_);
Client_SYS.Add_To_Attr('DOC_NO', doc_no_, attr_);
Client_SYS.Add_To_Attr('DOC_SHEET', doc_sheet_, attr_);
Client_SYS.Add_To_Attr('DOC_REV', doc_rev_, attr_);
Client_SYS.Add_To_Attr('DOC_TYPE', document_type_, attr_);
action_ := 'DO';
EDM_FILE_STORAGE_API.New__(info_,objid_,objversion_,attr_,action_);
--Following section creates the document EDM. Not needed since you don't have the document
--may be need some changes here
--Announce document write for event actions
--operation_ := 'WRITE';
--EDM_FILE_OP_ANNOUNCE_API.Announce_File_Operation(doc_class_,doc_no_,doc_sheet_,doc_rev_,operation_);
--Get EDM objid to be used for store input PDF blob
--EDM_FILE_STORAGE_API.Get_Obj_Id(objid_,objversion_,doc_class_,doc_no_,doc_sheet_,doc_rev_,document_type_);
--EDM_FILE_STORAGE_API.Write_Blob_Data (objversion_,objid_ ,file_data_ );
--Create doc reference
--Here I'm attaching to InventoryPart
--KEYREF should be in format KEY_1^...KEY_N^
Client_SYS.Clear_Attr(attr_);
Client_SYS.Clear_Attr(info_);
Client_SYS.Add_To_Attr('LU_NAME', 'InventoryPart', attr_);
Client_SYS.Add_To_Attr('KEY_REF', 'CONTRACT=' || Contract || '^PART_NO=' || PartNo || '^', attr_);
Client_SYS.Add_To_Attr('DOC_CLASS', doc_class_, attr_);
Client_SYS.Add_To_Attr('DOC_NO', doc_no_, attr_);
Client_SYS.Add_To_Attr('DOC_SHEET', doc_sheet_, attr_);
Client_SYS.Add_To_Attr('KEEP_LAST_DOC_REV', 'Fixed', attr_);
Client_SYS.Add_To_Attr('DOC_REV', doc_rev_, attr_);
Client_SYS.Add_To_Attr('COPY_FLAG', 'OK', attr_);
Client_SYS.Add_To_Attr('SURVEY_LOCKED_FLAG', 'Unlocked', attr_);
action_ := 'DO';
DOC_REFERENCE_OBJECT_API.NEW__( info_,objid_,objversion_,attr_,action_ );
end;
Cheers!
Damith
Your code is working as predicted. Very helpful. Unfortunate “someone” forgot to think before asking the question.
An empty file is, of course, not that useful. What is needed is templates containing a starting point. E.g. a CAD file containing all the predefined layers, styles etc.
I have rewritten your code to copy a document revision (template) and make a document connection to RoutingHead instead.
In workbench it looks like this:
Results:
Code:
/*
Copy document revision from doc_no=templateDocNo_
Create document connection to luName_ ='RoutingHead'
*/
declare
templateDocNo_ varchar2(2000):= '1004933';
contract_ varchar2(2000):='1';
order_no_ varchar2(2000):= &order_no;
release_no_ varchar2(2000):= &release_no;
sequence_no_ varchar2(2000):=&sequence_no;
old_doc_class_ varchar2(32000);
doc_class_ varchar2(32000);
doc_no_ varchar2(32000):='';
title_ varchar2(32000);
title_rev_ varchar2(32000);
copy_structure_ number:=0;
copy_app_route_ number:=0;
copy_file_ number:=1;
copy_access_ number:=1;
new_revision_ number:=0;
setrev_ number:=0;
setstate_ number:=0;
method_ number:=1;
copy_rec_ number:=1;
copy_corr_ number:=0;
format_size_ varchar2(32000):='';
copy_objects_ number:=0;
part_no_ varchar2(2000);
bom_type_db_ varchar2(2000);
routing_revision_ varchar2(2000);
title_sheet_ varchar2(2000);
attr_ varchar2(32000);
document_type_ varchar2(2000);
info_ varchar2(32000);
objid_ varchar2(32000);
objversion_ varchar2(32000);
lu_name_ varchar2(2000):='RoutingHead';
key_ref_ varchar2(32000);
begin
select r.doc_class into old_doc_class_ from DOC_ISSUE_REFERENCE r where doc_no= templateDocNo_;
select so.part_no, so.used_rout_bom_type_db, so.routing_revision into part_no_, bom_type_db_, routing_revision_
from shop_ord so where so.order_no=order_no_ and so.release_no=release_no_ and so.sequence_no=sequence_no_;
doc_class_:= old_doc_class_;
title_rev_:= Doc_Class_Default_API.Get_Default_Value_(old_doc_class_ ,'DocTitle','DOC_REV');
title_sheet_:= Doc_Class_Default_API.Get_Default_Value_(old_doc_class_ ,'DocTitle','DOC_SHEET');
title_:= part_no_;
doc_title_api.Copy_Doc_Title(old_doc_class_, templateDocNo_, doc_class_, doc_no_, title_, title_rev_, copy_structure_, copy_app_route_,
copy_file_, copy_access_, new_revision_, method_, setrev_, setstate_, copy_rec_, copy_corr_, format_size_, copy_objects_);
document_type_:= 'VIEW';
client_sys.Clear_Attr(attr_);
client_sys.Add_To_Attr('DOC_CLASS', doc_class_, attr_);
client_sys.Add_To_Attr('DOC_NO', doc_no_, attr_);
client_sys.Add_To_Attr('DOC_SHEET', title_sheet_, attr_);
client_sys.Add_To_Attr('DOC_REV', title_rev_, attr_);
client_sys.Add_To_Attr('DOC_TYPE', document_type_, attr_);
edm_file_storage_api.New__(info_, objid_, objversion_,attr_, 'DO');
key_ref_:= 'BOM_TYPE_DB='||bom_type_db_||'^CONTRACT='||contract_||'^PART_NO='||part_no_||'^ROUTING_REVISION='||routing_revision_||'^';
client_sys.Clear_Attr(attr_);
client_sys.Add_To_Attr('DOC_CLASS', doc_class_, attr_);
client_sys.Add_To_Attr('DOC_NO', doc_no_, attr_);
client_sys.Add_To_Attr('DOC_SHEET', title_sheet_, attr_);
client_sys.Add_To_Attr('DOC_REV', title_rev_, attr_);
client_sys.Add_To_Attr('COPY_FLAG', 'OK', attr_);
client_sys.Add_To_Attr('KEEP_LAST_DOC_REV', 'Fixed', attr_);
client_sys.Add_To_Attr('SURVEY_LOCKED_FLAG', 'Unlocked', attr_);
client_sys.Add_To_Attr('LU_NAME', lu_name_, attr_);
client_sys.Add_To_Attr('KEY_REF', key_ref_, attr_);
doc_reference_object_api.New__(info_, objid_, objversion_,attr_, 'DO');
commit;
end;
Hi,
Interesting hack! So, basically, you want, for some objects, there to be a “default document” that users can start editing directly, without having to create it first. I wonder if this is something others would like too. It would fit quite well as standard functionality, or perhaps we could at least provide a method to do it more easily for you, from a custom event or RMB… Things get a little bit harder if the template file is stored in FTP or Shared, but this can be solved too...
/Mathias
Hi,
This is the workflow I am working at.
When we receive an order for a new part from the customer:
When the customer re-order the part, the CAM-file will be visible to shop floor because it is attached to the routing head LU.
If the customer provide new revision of the files, sales create a new routing revision an place the files there. To Identify the changes to the files, we need a way to compare the pdf-files (I talk about that Here. We are also in talks with some AI-companies regarding this).
Other challenges
Now
Interesting workflow, I hope you will get it to work. There’s a lot to comment about there, and ask questions, but I don’t have the time to do that.
- Not sure what you meant with “When the operator create the new file in workbench, he cannot delete it, because it is in another LU.”
If the operator accidentally create the wrong file.
Aha. It is true, and it is on purpose, that you cannot detach “derived” documents. But can’t he/she simply go to another screen to do that work (or perhaps use the document - object connections overview screen)? Of course it will be a small hassle but it should not happen often, right?
Very nice thread with lots to learn from. Thanks for all input.
Steve
Hi,
Interesting hack! So, basically, you want, for some objects, there to be a “default document” that users can start editing directly, without having to create it first. I wonder if this is something others would like too. It would fit quite well as standard functionality, or perhaps we could at least provide a method to do it more easily for you, from a custom event or RMB… Things get a little bit harder if the template file is stored in FTP or Shared, but this can be solved too...
/Mathias
Hi,
Interesting hack! So, basically, you want, for some objects, there to be a “default document” that users can start editing directly, without having to create it first. I wonder if this is something others would like too. It would fit quite well as standard functionality, or perhaps we could at least provide a method to do it more easily for you, from a custom event or RMB… Things get a little bit harder if the template file is stored in FTP or Shared, but this can be solved too...
/Mathias
No, this has not been implemented. In fact, I think no one has created an idea for it here on IFS Community. Perhaps you will be the first one?
And, it might be possible to do this using BPA, yes. The devil is in the detail though, and someone need to give it a try to know the answer.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.