cancel
Showing results for 
Search instead for 
Did you mean: 

how can i get the current version of a contract document via beanshell?

Former Member
0 Kudos

Hallo Community.

i can't find any way to get directly the current version of a contract document.

i iterate now over all doc versions and extract the version of each document from the display name like this:


public String getDocLastVersion(IBeanIfc bean) {

    verColl = bean.getDocVersions();

    verIter = verColl.iterator();

    int verStart = 0;

    while(verIter.hasNext()) {

        verBean = verIter.next();

        name = verBean.getDisplayName();

        if (!name.isEmpty()) {

            i = name.lastIndexOf("(");

            j = name.lastIndexOf(")");

            if ((i > 0) && (j > 0) && (j > i) && (j <= name.length() && (i< name.length()))) {

                temp = name.substring(i + 1, j);

                int verTemp = Integer.parseInt(temp);

                if (verTemp > verStart) {

                    verStart = verTemp;

                }

            }

        }

    }   

    return Integer.toString(verStart);

}

i'm not happy with this solution.

if the document name is over 38 chars long there is no version stored in display name, because display name is limited to 40 chars

there must be other way to get the document version.

can somebody help me with this?

thank you

Waldemar

Accepted Solutions (1)

Accepted Solutions (1)

former_member190023
Contributor
0 Kudos

A more effective way would be to use below statement in your loop

version = verBean.getFieldMetadata("VERSION").get(bean);

You'll get the version as Integer and will be a lot more readable.

It doesn't look like the public api exposes any method for directly fetching the current (or last) version.

Some internal apis could be there but require investigation.

Bogdan

Former Member
0 Kudos

thank you very much - this solution solved my problems

former_member190023
Contributor
0 Kudos

Your code looks very nicely formatted. Are you using this by any chance?

Bogdan

Answers (0)