How to create a new type in Alfresco

In this tutorial, we explain how to create a new type in Alfresco. To do that, we are implementing a quite simple example.

Let’s say we work in the Human Resources department, and we are looking for an expert in Alfresco and we want to keep the candidates’ information in our Alfresco repository. For that purpose, we will add a new type to store their resumes. This document type will have two properties: status and decision.
The status will have the values “Under review” and “Ready”.

1. Add your name space
Go to content-model.xml, and add a custom namespace for your custom model. In our case, we are going to use “ex”

<!-- Custom namespace -->
  <namespace uri="" prefix="ex" />

2. Create a constraint list to set the allowed values for the property status

  <constraint name="ex:allowedStatus" type="LIST">
    <parameter name="allowedValues">
        <value>Under Review</value>

3. Add the type’s definition

  <!-- CV type -->
  <type name="ex:cv">
      <property name="ex:status">
          <constraint ref="ex:allowedStatus"/>
      <property name="ex:decision">

Now, you have your custom type ready!

4. Change share-config-custom.xml to make the new type available in the change type list in Share
You can have a model in Alfresco, but that doesn’t mean that Share will use it directly. It’s necessary to define in Share how the new type will be displayed. To add this configuration, go to share-config-custom.xml and include your custom type as a subtype of “cm:content”

  <type name="cm:content">
    <subtype name="ex:cv" />

5. Add a label for your custom type
Go to web-extension/messages/* and add a name for your type, using the following syntax:

#Names for types

6. Set the fields’ visibility
Add in share-config-custom.xml

<!-- ex:resume -->
<config evaluator="model-type" condition="ex:cv">
        <show id="ex:status" force="true"/>
        <show id="ex:decision" force="true"/>

And voilà

custom type alfresco