javafilenet-p8

How to get the property data type in FileNet P8


In FileNet P8, I need to get the datatype of the property of a custom class using JAVA API. Is there any way to do the same?


Solution

  • This should give you an idea of what you need to do:

        //SymbolicName of the property we will search for.
        String strSearchName = PropertyNames.DATE_LAST_MODIFIED;
        //Document (or other object) that we will use to get classDescription.
        Document document = (Document) arg0; 
    
        PropertyDescription objPropDesc = null;
        PropertyDescriptionList pdl = document.get_ClassDescription().get_PropertyDescriptions();
        Iterator<?> iter = pdl.iterator();
        while (iter.hasNext())
        {                                               
            objPropDesc = (PropertyDescription) iter.next();                      
    
           // Get SymbolicName property from the property cache
           String strPropDescSymbolicName = objPropDesc.get_SymbolicName();
    
           if (strPropDescSymbolicName.equalsIgnoreCase(strSearchName))
           {
              // PropertyDescription object found
              System.out.println("Property description selected: " + strPropDescSymbolicName);
              System.out.println(objPropDesc);
    
              TypeID type = objPropDesc.get_DataType();
              System.out.println(type.toString());
              break;
           }
        }
    

    The idea is to:

    1. Take an object (Document in this case).
    2. Get its Class Description.
    3. Get the list of Property Descriptions from the Class Description.
    4. Loop through the Property Descritpions until you locate the Description you are trying to find.
    5. Get the TypeId from the Property Description.
    6. The TypeId contains the information you need to know what the Type is of the Property.

    I borrowed code from here : Working with Properties

    You should also familiarize yourself with this : Properties

    Edit to add a different method:

    In the case of creating documents, we need to be able to obtain the Class Description object. This means we will need to perform additional round trips.

    // Get the ClassDescription
    String strSymbolicName = "myClassName";
    ClassDescription objClassDesc = Factory.ClassDescription.fetchInstance(myObjStore, strSymbolicName, null);
    
    // find the PropertyDescription     
    PropertyDescription pds = null;
    PropertyDescriptionList pdl = objClassDesc.get_PropertyDescriptions()‌​;
    Iterator<?> itr = pdl.iterator();
    while(itr.hasNext()){ 
        pds = (PropertyDescription) itr.next();
        System.out.println("Symbolic Name is "+pds.get_SymbolicName()+" DataType is "+pds.get_DataType().toString()); 
    }
    
    // You can now use it in a loop of several documents if you wish.
    ...
    

    Take a look here as well : Working With Classes