Content Management and Capture

Content Management and Capture

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
Expand all | Collapse all

Retrieving all versions of a document using SQL query

  • 1.  Retrieving all versions of a document using SQL query

    Posted Tue January 05, 2021 12:29 AM

    I'm looking for a way to retry and if needed remove all documents located inside the tree of a given folder root with all of their versions, not just the current one.

    The easiest way might be a SQL query with a batch deletion. Since previous version of a document are not filed in a Folder, I proceeded to do it this way:

    • Perform a SELECT request on Document class
    • Add a left join between a document version (Document as doc) and other versions (Document as doc2) using version_series key.
    • Filter to get only current version from other versions (doc2.IsCurrentVersion = true)
    • Filder to get only documents whose current version is filed in a given Folder tree (INSUBFOLDER clause)

    Additional step:

    • Left joins with ReferentialContainmentRelationShip and Folder classes to get the Path Name of the document current version Folder

    The final request looks like below:

    SELECT doc.this, doc.majorversionnumber AS "MAJV", doc.minorversionnumber AS "MINV", doc.IsCurrentVersion as "Is Current", doc2.This as "Current version", f.pathname As "Current version folder"FROM ((Document doc LEFT JOIN Document doc2 ON doc2.VersionSeries = doc.VersionSeries) LEFT JOIN ReferentialContainmentRelationShip rcr ON doc2.VersionSeries = rcr.VersionSeries)LEFT JOIN Folder f on f.This = rcr.tailWHERE doc2.IsCurrentVersion = true AND doc2.this INSUBFOLDER '/path/to/folder'/'ORDER BY doc2.This

    Is a good and not overkill way to achive what the goal?



    #FileNet
    #Support
    #SupportMigration


  • 2.  RE: Retrieving all versions of a document using SQL query

    Posted Thu January 07, 2021 04:48 PM

    Are you doing the join only to get all versions of a document? If yes, that would seem an overkill to me. Something like

    WHERE IsCurrentVersion in (true, false)

    looks sufficient to me.

    I think there is even an easier way, but can't remember what it was :-(

    /gerold



    #FileNet
    #Support
    #SupportMigration


  • 3.  RE: Retrieving all versions of a document using SQL query

    Posted Thu January 07, 2021 05:18 PM

    Hello Gerold,

    Thanks for your answer. I'm not sure to understand your WHERE clause. Are you suggesting this:

    SELECT This From Document WHERE IsCurrentVersion in (true, false)

    Such request would return all Documents.

    Regards.



    #FileNet
    #Support
    #SupportMigration