Versioning a KM Document
Use
The example below shows how to implement custom code in your application so that you can create different versions of a KM Document.
Procedure
- Create a new application:
More information: Creating Composite Application Development Components .
- Create an application service in your application:
More information: Creating Application Services .
- Set dependency to DocContent, Document, and RelatedObject:
More information: Defining Application Service Dependencies .
- To enable document versioning, import the following code in the implementation of the operation:
DocContentServiceLocal docContentLocal = getDocContentServiceLocal(); Collection<String> rids = docContentLocal.getRelatedObjectRids(docKey); String rid = rids.iterator().next(); if ( !docContentLocal.isDocumentVersioned(rid)) docContentLocal.enableDocumentVersioning(rid);
- To check out the document for editing, import the following code in the implementation of the application service:
docContentLocal.checkout(rid);
- To check in the new version of the document, import the following code:
byte[] contentVer2 = getResFileContentVersion2(); docContentLocal.checkin(rid, contentVer2); - To get the whole version history of the document, import the following code:
String [] versionHistoryRidsArrStr = (String []) docContentLocal.getVersionHistory(rid).toArray(new String[0]);
- To set a version of a document as current version:
docContentLocal.setAsCurrentVersion (versionHistoryRidsArrStr[versionHistoryRidsArrStr.length -1], rid);