1

How to fetch the PropertyTemplate by symbolic name and appended to Custom Object class through IBM FileNet CE API

1 Answer 1

2

You can use the following function to fetch the property template:

public PropertyTemplate getPropertyTemplate(String name, ObjectStore objectStore ) 
{
    String queryFormat = "SELECT [This] FROM [PropertyTemplate] WHERE ([SymbolicName] = ''{0}'')";      
    SearchScope scope = new SearchScope( objectStore );
    String query = MessageFormat.format(queryFormat, name );
    RepositoryRowSet fetchRows = scope.fetchRows(new SearchSQL( query ), null, null, null );
    Iterator<?> iterator = fetchRows.iterator();
    if ( !iterator.hasNext() )
    {
        return null;
    }

    RepositoryRow row = (RepositoryRow) iterator.next();
    return (PropertyTemplate) row.getProperties().getObjectValue("This");
}

And then use the following code to add the property template to the class:


PropertyTemplate propertyTemplate = getPropertyTemplate(name, objectStore);
ClassDefinition classDefinition = Factory.ClassDefinition.fetchInstance(objectStore, className, null);
PropertyDefinition propertyDefinition = propertyTemplate.createClassProperty();

// Set some additional properties on the property definition 
// to override template defaults

classDefinition.get_PropertyDefinitions().add(propertyDefinition);
classDefinition.save(RefreshMode.NO_REFRESH);

Not the answer you're looking for? Browse other questions tagged or ask your own question.