raviteja
raviteja

Reputation: 135

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

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

Upvotes: 1

Views: 646

Answers (1)

Ricardo
Ricardo

Reputation: 411

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);

Upvotes: 2

Related Questions