version-controlversionecmdfcdocumentum-dfc

How to get CURRENT version label number through DFC code?


public static IDfCollection getVersions() {
    IDfQuery query = clientX.getQuery();// obtain an idfObject
    query.setDQL(
            "select r_object_id,object_name,r_version_label,owner_name from dm_document(all) where i_chronicle_id='090008868006d5be'");
    IDfCollection collection = null;
    try {
        collection = query.execute(SessionFile.getSession(), IDfQuery.DF_READ_QUERY);
    } catch (DfException e) {
        e.printStackTrace();
    }
    return collection;

}

public class Versions {
public static void main(String[] args) {
    IDfCollection collection = AllOperations.getVersions();
    try {
        int versionsCount = collection.getValueCount("r_object_id");
        //IDfSysObject dfSysObject=(IDfSysObject) SessionFile.getSession().getObject(new DfId("09000886800a143e"));
        while (collection.next()) {
            //String versionNum = dfSysObject.getVersionLabels().getImplicitVersionLabel();
            int i = 0;
            while (i < versionsCount) {
                System.out.println(collection.getRepeatingValue("r_version_label", i));
                i++;
            }
        }
    } catch (DfException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

Output of the above code is: 1.0, 1.1, 1.2, CURRENT

enter image description here

in place of "CURRENT" label, I want to "get version number" like 2.0 or 3.0 etc which is latest document version number.

needed output like below :

enter image description here


Solution

  • First of all, this line:

    int versionsCount = collection.getValueCount("r_object_id");
    

    should rather be

    int versionsCount = collection.getValueCount("r_version_label");
    

    and has to be in the while(collection.next()) loop, this way it will properly iterate over all r_version_label values, so the code will now output:

    1.0
    1.1
    1.2 
    CURRENT
    2.0
    

    you can now get rid of CURRENT (or in general get rid of all non values which can't be parsed to a float number).