Documentum provides the Documentum Foundation Classes(DFC) as a Java library to connect to Documentum. When dealing with documents, it may be necessary to get prior versions, instead of the current version. But the sessionManager methods like getObjectByQualification seem to only work on the current r_object_id or current version of that document. Searching by r_object_id returns null or throws an exception.
In order to get older versions of the document, you must add ALL when you do getObjectByQualification(). Then you can get the prior or previous document or file without having to delete or destroy the latest one in any way. Below is a code example.
A similar thing can be done to find repeating attributes such as r_version_label. But in that case, the keyword is ANY:
The above can also be done directly in a DQL query. But this post is for people who don't know how to use DQL or who want to build on what they learned in the DFC Development Guide.
In order to get older versions of the document, you must add ALL when you do getObjectByQualification(). Then you can get the prior or previous document or file without having to delete or destroy the latest one in any way. Below is a code example.
import java.io.*; import com.documentum.fc.client.IDfSession; import com.documentum.fc.client.IDfSessionManager; import com.documentum.fc.client.IDfSysObject; public class OlderVersions { public static String getOlderVersion( String repositoryName, IDfSessionManager sessionManager, String documentName) { IDfSession mySession = null; try { mySession = sessionManager.getSession(repositoryName); // search for the object using the filename IDfSysObject existingDoc = (IDfSysObject) mySession.getObjectByQualification( "dm_document (ALL) where object_name='" + documentName + "'" ); if (existingDoc != null) { //object with that filename exists //then extract the contents of the file ByteArrayInputStream dumpedCorrection = existingDoc.getContent(); } else { System.out.println("no file found for " + documentName); } } catch (Exception ex) { ex.printStackTrace(); } finally { // release the session sessionManager.release(mySession); } } }
IDfSysObject existingDoc = (IDfSysObject) mySession.getObjectByQualification( "dm_document where object_name='" + documentName + " and any r_version_label='THE_LABEL_NAME_YOU_USE''" );