cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to extract Attachments from Blob files into an FTP location

tridip_chakraborthy
Contributor
0 Kudos

Folks,

Lets say, i want to take an image of all of my SAP CLM Contract Attachments into SharePoint, like a migration approach, where we brought legacy contracts into SAP CLM.

Is there a way to Extract all of the Attachments from the Blob Files that point to different Business Objects RFX, Contracts, Projects etc into an FTP folder.

The use-case is as follows

1) My SAP CLM/Sourcing Attachment Data sits today in the form of Blob files in an Oracle DB

2) I want to use SharePoint as a centralized Document management system even if CLM has the capability, since SharePoint is my Document Lifecycle Management system of record for my company.

3) I need to Extract all the attachments and put it into an FTP location that points to my SharePoint system

4) Does the export to OMA option help me further tether the OMA into individual attachments, I really dont know?

...I will take it from there

All the expert advice that I need is, How do I extract my attachments from Oracle Blobs to real attachments into an FTP or a Network or a Local folder

is this possible, how?

...time for the Gurus to respond

Cheers

Tridip

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Tridip,

I am using AttachmentIfc ->setFileData() method to set a file as an attachment to MA/SA. But did not find getFileData() or any other method in this class to get the attached file. looks like SAP didn't provided any API for this functionality.

Below is the one option, but haven't tested.

Writing a jar file. Use java class IapiDbHandleIfc and method executeQuery()  by passing below  query 

Select T1.UNIQUE_DO_NAME, T3.FILE_DATA From FCI_CONTRACT/ FCI_AGREEMENT T1 join  FCI_ATTACHMENT_SUB T2  on ( t2.PARENT_OBJECT_ID = T1.ObjectId) Join FCI_ATTACHMENT_BLOB   T3 on  (t3.PARENT_OBJECT_ID = T2.ObjectId)

Parse the result set and store the BLOB value into FileOutputStream, where it creates the file in the path provided to it.

Hope this helps you.

Thanks
Sai

Former Member
0 Kudos

Tridip / Sai,

You can extract the documents from CLM by doing the following steps:

1. Get all the versions of the contract documents attached on a contract document tab. If you do it in a script on contract document, you might want to do:

          doc.getDocVersions();

This gives a collection of contract documents (.doc files) attached on a contract document tab, the latest document being the first in the collection.

2. Iterate on the collection to choose the file of your choice or choose the first element to pick the latest version file.

     DocumentVersionIBeanIfc docVersionBean = doc.getDocVersions().get(0);

3. Once you get the latest DocumentVersion, you can get the actual document in attachment by doing:

     AttachmentIfc  attachment = docVersionBean.getDoc();

  

4.  To retrieve the file from the attachment as java.io.File object, you can do:

  

      File file = attachment.getFileData(session);

And from here, you can use the file as you wish to.

However, you might want to note one important thing while doing the above steps. The method call in step 4 is not available in  com.sap.odp.api.common.types.AttachmentIfc class. You must use the following import apart from the AttachmentIfc import.

import com.sap.odp.common.types.Attachment;

Hope this helps!

Thanks,

Bindu

tridip_chakraborthy
Contributor
0 Kudos

Hi Bindu

Thanks a lot for the guidance

I wanted to further check with you, where to write these queries, on the application front end using query definition scripting or directly in the DB?

Pls let me know

thanks

Tridip

Former Member
0 Kudos

Hi Tridip,

You can write this in scripting context (script definitions) or create an IAPITask (this can be configured as a background task too). Both of them would work. Query definition would not allow you to use CLM IAPI library. You can only write SQL scripts in there as far as my knowledge goes.

Hope this helps!

Thanks,

Bindu

Former Member
0 Kudos

Hi Bindu,

     Can you please advice us how to run this script to extract the attachments out the CLM system.

Thanks

Chosor.

Former Member
0 Kudos

Hi Chosor,

How to run the script depends on when you want to extract the document out. In my case, we have extracted the document to send it to people involved in approval process for digital signatures. We have done this on a phase change and hence had the script on Contract Document lifecycle event -> Post Phase Change (target)

Now, it depends on what your requirement is to choose an appropriate scripting context.

Let me know if it makes sense.

Regards,

Bindu

Former Member
0 Kudos

Hi Bindu,

I have similar kind of requirement. I need to get the list of contract documents for a Master Agreement.


I have tried the steps that you have provided, But I could not get the list and getting error "doc.getDocVersions();" this method is not available in conractdocumentimplifc.


I tried your steps in "Contract post phase change script".


I have imported the necessary packages too, but don't know where I am missing.

Could you please post the full code which you have implemented for this.

Thanks

Raj

Former Member

Hi Bindu,

I need to extract the attachments from all the contract documents in a Master Agreement to the development system directory location. This is my requirement. I wrote and ran this script in my CLM development environment, which generates the attached files of that contract document in the location D:/usr/sap/ESD/esourcing51/ in my CLM development server successfully.

After running this script, the attached files generated as script output are showing correctly if that file’s format type is text (.txt), but if that file format type is MS Word document (.doc), then this doc file is not opening and giving error when I try to open that word file. As I came to know that CLM development server is having Microsoft word 2003 version installed only and due to any of these following reasons, it is throwing the error as shown in attached document with this mail :

1.      CLM development server does not allow this generated word document file and giving this error while opening it because it seems to be some MS Word  version issue. This is the probable reason for this error.

2.      Check the file permissions for the document or drive. (I ruled out this reason : gave full permissions to file, even then unable to open it. Refer Attachment)

3.      Make sure there is sufficient memory & disk space. (I ruled out this reason: the disk has 28 GB free space, even then unable to open it. Refer Attachment)

4.      Open the  file with the Text Recovery converter (I ruled out this reason :  This software is not installed on development server.)

Moreover, I have also uploaded some dummy test document of version MS word 2010 into the Contract document of the master agreement, even then I am still getting the same error message while opening the generated word file  after downloaded and installed a compatibility pack.

I am writing the same code and importing same package too in my attached script as suggested by you in your above post, even then I am having issue in case of only Microsoft Word document type attachments in my contract documents. I have attached my script with this post for your reference.

Could you please advise me how we can fix this error.

Thanks,

Amit Gilotra

mahesh_damodar
Explorer
0 Kudos

Hi Bindhu and Amit,

I have the same questions and posted in the thread below. Please check and help me soon

Extract clm documents

https://answers.sap.com/questions/12674711/extract-clm-contract-documents-pdf-from-sap-clm.html

Answers (3)

Answers (3)

mahesh_damodar
Explorer
0 Kudos

Hi Bindhu and Amit,

I have the same questions and posted in the thread below. Please check and help me soon

Extract clm documents

https://answers.sap.com/questions/12674711/extract-clm-contract-documents-pdf-from-sap-clm.html

0 Kudos

Hello Experts,

I was able to retrieve the attached documents from the Blob files using the steps provided by Bindu.

Once I have the file with getFileData method, do you know how I can set this file in a FTP location?

I have tried to use the standard Java method to upload file to FTP but I get error executing the following method:

FTPClient ftpClient = new FTPClient();

Thanks in advance!

Best Regards,

Fran.

Former Member
0 Kudos

July 22, 2014:  Qx:  Has anyone actually gotten this work from any place but the contracts tab?

I invoke script NOT from the tab, and I get to the attachements via the KDOCS collection.

I I can see the actual file-names that were orginally attached, and other details in the collection.

However, I am not able to invoke the find a way to get into an attachment object for downloading.

I have tried using the DocumentVersionIBeanIfc interfac via approachs referenced in SCN.

My script will let me import it, but I can invoke or use the any of the methods reference in these threads.  I have tried, (import, using homelocater, casting)

the ideal approach is the one discribed in this thread.,

    AttachmentIfc  attachment = docVersionBean.getDoc();   . . .

    File file = attachment.getFileData(session);

But I can't find a "getFileData() method anywhere, I do see a setFileData method,  we use that to import our attachments, and add them to the KDOCS collection.

I have tried several approachs, and this has worked best for me.

But currently I am blocked on "how to get my collction references in an I/O attachment".

Any suggestions?

   code is someting like this:

    . . .

   madoc.getExtensionCollection("COLLN_KDOCS");                   //masterAgreement

   . . . 

   currentKD =   newKD.getExtensionField("KDOC_FILE").get();  //interating over the collecton

   I know that above snippet returns what I expect,I can verify via sql and logging.

   However, getting this blob wired up to an attachment is proving difficult for  me.

   I tried some items like this too:  

    AttachmentIfc kdAttach;                    //currentKD
    kdAttach = TypeFactory.createAttachment();
    kdAttach = madoc.getAttachments();  // madoc is the reference I used to get a handle to the kdcod   collection above


error returns:  "Illegal cast. Cannot cast com.sap.eso.api.contracts.ContractIBeanImpl$1 to com.sap.odp.api.common.types.AttachmentIfc"

  I am not a java developer by trade, just a developer.

 

  So I ask again, has anyone actually downloaded the blobs  NOT from the contracts tab?

your thoughtful response and time is greatly appreciated, Beth

Former Member
0 Kudos

Hi Beth,

As I mentioned in my response earlier in this thread, you should be able to retrieve the attached documents given that you follow the steps in the same order. I would like to re-iterate the following:


"However, you might want to note one important thing while doing the above steps. The method call in step 4 is not available in  com.sap.odp.api.common.types.AttachmentIfc class. You must use the following import apart from the AttachmentIfc import.

import com.sap.odp.common.types.Attachment;

I have successfully retrieved the attached contract documents on contract documents tab using this approach.

Hope you will be able to do as well. Let me know if you would like to show me your code so that we can go through it together and see if we can fix it.

Regards,

Bindu Sharma

Former Member
0 Kudos

Thank you Bindu for responding.  I am honored by your reply.


For me, I am not able to get valid reference using the DocumentVersionIBeanIfc interface.  My script is not running from the contracts tab, and hence when I try to ge the doc, my calls are sucessfull, for the pointer is always null.

I am able to get a collection using my mastergreement interface, and I have valid collection.

 

From you reply, I was able to see that I HAD NOT actully imported the types pacage.  *thansk again</p><p> </p><p>Now I have these imports explicitylly in my script:</p><p><span style="font-size: 10pt;"></span></p><p>    import<span style="text-decoration: underline;"><span style="color: rgb(127, 0, 85); font-size: 10pt;"><span style="color: rgb(127, 0, 85); font-size: 10pt;"></span></span></span><span style="color: rgb(127, 0, 85); font-size: 10pt;"><span style="color: rgb(127, 0, 85); font-size: 10pt;"></span></span><span style="font-size: 10pt;">  <span style="text-decoration: underline;">com.sap.odp.api.common.types.AttachmentIfc</span>;</span></p><p>    import<span style="text-decoration: underline;"><span style="color: rgb(127, 0, 85); font-size: 10pt;"><span style="color: rgb(127, 0, 85); font-size: 10pt;"></span></span></span><span style="color: rgb(127, 0, 85); font-size: 10pt;"><span style="color: rgb(127, 0, 85); font-size: 10pt;"></span></span><span style="font-size: 10pt;">  <span style="text-decoration: underline;">com.sap.odp.common.types.Attachment</span>;</span></p><p>    import*  ;

 

 

It seems to me that I am sucessfully "wiring-up" the attachment to my desired document ( i.e. kd-doc attachemnet ).

At this point the script manager won't build and is giving this error:

 

    Document Lifecycle Event (userdefined.md5. Validated) script exception: 

    Sourced file: inline evaluation of: " Typed variable declaration : Attempt to resolve method: getFileData() on undefined variable or class name: attachment"

I have posted the relevant code, and one can see i am getting attachment object of correct type, and via my IDE, I can see the method .getFileData(), however someting in my evironment, install, or ?? seems to be block me from using the method at script invocation time.

 

Again,  the best method , step 1  doc.getDocVersions(); isn't going to work in my case becusee I don't have a current  document. 

 I have to use the method below to get the docs/ibeans.

     

maDocVerHome =

IBeanHomeLocator.lookup(session, com.sap.eso.api.doccommon.doc.contract.DocumentVersionIBeanHomeIfc.sHOME_NAME);

masterAgreementHome =

 IBeanHomeLocator.lookup(session, com.sap.eso.api.contracts.ContractIBeanHomeIfc.sHOME_NAME);

. .

 

madoc  = masterAgreementHome.findForEditByUniqueDocName((String) maUDN); // works well for use this is my doc.()

kddoc   = maDocVerHome.findForEditByUniqueDocName((String) maUDN);            //returns a null pointer

 

//step 1 doc.getDocVersions();


kddoc.getDocVersions();  //sucessful call but result

//step 2 DocumentVersionIBeanIfc docVersionBean = doc.getDocVersions().get(0);

!/servlet/JiveServlet/downloadImage/504520/Capture.PNG|height=382|alt=Capture.PNG|width=699|class=jive-image-thumbnail jive-image|src=/servlet/JiveServlet/downloadImage/504520/Capture.PNG!

 

 

   My step 1 and step 2 differed from your approach, but I think step 3 is working, from my log results.  However, I don't understand what is happing with the .getFileData(), clearly the code is in the jar.  Suggestions?

 

Thank you again for your time and helpful response, Beth

 

 

Former Member
0 Kudos

Much regrets on poor post,  I tried the advanced editor.  😞

Former Member
0 Kudos

Thank you Bindu for responding.  I am honored by your reply.

For me, I am not able to get valid reference using the DocumentVersionIBeanIfc interface.  My script is not running from the contracts tab, and hence when I try to ge the doc, my calls are sucessfull, for the pointer is always null.

I am able to get a collection using my mastergreement interface, and I have valid collection.

From you reply, I was able to see that I HAD NOT actully imported the types pacage.  **thansk again**

Now I have these imports explicitylly in my script:

    import  com.sap.odp.api.common.types.AttachmentIfc;

    import  com.sap.odp.common.types.Attachment;

    import  com.sap.eso.api.doccommon.doc.contract.DocumentVersionIBeanIfc;

It seems to me that I am sucessfully "wiring-up" the attachment to my desired document ( i.e. kd-doc attachemnet ).

At this point the script manager won't build and is giving this error:

    Document Lifecycle Event (userdefined.md5. Validated) script exception:

    Sourced file: inline evaluation of: " Typed variable declaration : Attempt to resolve method: getFileData() on undefined variable or class name: attachment"

I have posted the relevant code, and one can see i am getting attachment object of correct type, and via my IDE, I can see the method .getFileData(), however someting in my evironment, install, or ?? seems to be block me from using the method at script invocation time.

Again,  the best method , step 1  doc.getDocVersions(); isn't going to work in my case becusee I don't have a current  document.

I have to use the method below to get the docs/ibeans.

    

kddoc   = maDocVerHome.findForEditByUniqueDocName((String) maUDN);             //returns a null pointer

//step 1  doc.getDocVersions();

kddoc.getDocVersions();  //sucessful call but result

//step 2 DocumentVersionIBeanIfc docVersionBean = doc.getDocVersions().get(0);

   My step 1 and step 2 differed from your approach, but I think step 3 is working, from my log results.  However, I don't understand what is happing with the .getFileData(), clearly the code is in the jar.  Suggestions?

Thank you again for your time and helpful response, Beth