Search code examples
javaxpageslotus-notes

ViewEntry - columnValues.get(0) sometimes multivalue column


I want to collect the values in a first sorted categorized view column.

However, sometimes the values can be multivalue due to the column formula:

names := @If(Form = "project"; projectManager : projectCustomer;                            Form = "budget"; docAuthors; Form = "plan"; "docOwners"; "[Unknown]");

@Return(@Name([Abbreviate];@Unique(names)))

Some fields are single value, some are multi-value.

I tried

Vector<String> names= entry.getColumnValues();
String name = String.valueOf(names.get(0));

but this converts the array to a string

Vector<String> names= entry.getColumnValues();
String name = names.get(0);

breaks the code.

Anyone have a suggestion to get the value(s) from the column?


Solution

  • Have you tried to check the type of the value? Something like this:

    Vector<?> data = entry.getColumnValues();
    Object tmp = data.get(0);
    Vector<?> result = new Vector();
    
    if( tmp instanceof String ){
        result.add( (String) tmp );
    }
    
    if( tmp instanceof ArrayList ){
        ArrayList list = (ArrayList) tmp;
        for( int i=0; i<list.size(); i++ ){
            result.add( list.get(i) );
        }
    }
    
    if( tmp instanceof Vector ){
        Vector<?> vec = (Vector) tmp;
        for( int i=0; i<vec.size(); i++ ){
            result.add( vec.get(i) );
        }
    }
    
    
    return result;
    

    Then you will always get a Vector with all the values (even it is a single value only)