2

I want to delete documents for which a specific property has been set in the current version. If this property has been set all versions of that document need to be removed. My current implementation which searches for IsCurrentVersion = TRUE and foo = 'bar' has the problem that only the current version gets removed and not the older ones. So I assume that I need to delete the complete VersionSeries ? Till now I use

doc.delete();
doc.save(RefreshMode.NO_REFRESH);

for each document I find. How can I retrieve all documents from the series and have them deleted too ? And is it more efficient if I add this to a batch ?

Marged
  • 10,577
  • 10
  • 57
  • 99
  • if you want to have a more efficient delete(lots of files to edit or delete) checkout this: http://www-01.ibm.com/support/knowledgecenter/SSNW2F_5.2.0/com.ibm.p8.ce.dev.ce.doc/batch_procedures.htm?cp=SSNW2F_5.2.0%2F10-2-1-4-0 with the batch api you can bundle the save actions to save on roundtrips to the server. – Robert vd S Mar 30 '15 at 12:11

2 Answers2

10

You should call the

delete()

method for the VersionSeries (http://www-304.ibm.com/support/knowledgecenter/SSNW2F_5.2.0/com.ibm.p8.ce.dev.java.doc/com/filenet/api/core/VersionSeries.html) instance,

VersionSeries vs = doc.getVersionSeries();
vs.delete();
vs.save(Refresh.NO_REFRESH);

Quote from docs

Caution: The delete and moveContent methods impact all document versions in the version series. That is, all document versions are deleted, and the content of all document versions are moved.

swepss
  • 481
  • 3
  • 9
1

Method for deleting all the versions of a document from FileNet

public void deleteDocumentFromCE(String filenetDocGUID) throws Exception 
{
    System.out.println("In deleteDocumentFromCE() method");
    System.out.println("Input Parameter filenetDocGUID is : " + filenetDocGUID);

    Document document = null;
    UserContext uc = null;
    ObjectStore os = null;
    Subject subject = null;
    VersionSeries vs = null;

    try 
    {
        if (filenetDocGUID != null) 
        {
            getCESession(); //This method will get the CE session and set it in ceSessionData private class variable

            os = ceSessionData.getObjectStore();
            System.out.println("ObjectStore fetched from CESession static reference is : " + os.get_Name());

            subject = ceSessionData.getSubject();
            System.out.println("Subject fetched from CESession static reference.");

            uc = UserContext.get();
            uc.pushSubject(subject);

            if (os != null) 
            {
                document = Factory.Document.fetchInstance(os, filenetDocGUID, null);
                vs = document.get_VersionSeries();
                vs.delete();
                vs.save(RefreshMode.NO_REFRESH);
                System.out.println("All Document Versions deleted : " + filenetDocGUID);

            }
            else
            {
                System.out.println("Error :: Object Store is not available.");
            }
        }
    }
    catch (Exception e) 
    {
        System.out.println("Exception in deleteDocumentFromCE() Method : "+ e.getMessage());
        //pass the error to the calling method
        throw new Exception("System Error occurred while deleting the document in CE.. "+e.getMessage());
    }
    finally 
    {
        if (uc != null)
            uc.popSubject();
    }

    System.out.println("End of deleteDocumentFromCE() method");
}
Sourabh
  • 413
  • 5
  • 17