How do I set default value for Alfresco aspect property that can be multiple?

Viewed 293

I have to prepopulate my model with all options from constraint. How do I set a default value for an aspect property in Alfresco that have multiple flag set to true? Is it even possible to pass array of items to default value?

<property name="aa:allowedTypes">
   <title>Allowed types</title>
   <type>d:text</type>
   <multiple>true</multiple>
   <default>cat,dog,chicken</default>
   <constraints>
     <constraint ref="aa:allowedTypesOption" />
  </constraints>
</property>

<constraints>
    <constraint name="aa:allowedTypesOption" type="LIST">
      <parameter name="allowedValues">
        <list>
          <value>cat</value>
          <value>dog</value>
          <value>chicken</value>
        </list>
      </parameter>
    </constraint>
</constraints>

It seems that cat,dog,chicken does not work, nor does ["cat","dog","chicken"]

Edit: Yep, there is no solution to this. It can be set up to fill this field on node creation with policy but not in model.

3 Answers

By default it is not possible to set multiple default values. default tag in content model is meant to set a single value, not designed to put multiple.

However, you can achieve this by implementing a rule/behavior which can set the multiple values at the time of node creation.

Have you considered using the Model Manager in Alfresco to accomplish your task.

You can have a "List of Values" for a property of a "Custom Type" and there is field for "Default Value" as well. However I cannot say the same for when creating an "Aspect" and I do not see how an array of values can be passed within the creation of an aspect.

You cannot set multiple default values for an aspect property.

But you can achieve this by using any of the below Node Service policies. For Ex: you can set multiple values using the method onAddAspect. Before adding the corresponding aspect you can do whatever customizations you want.

org.alfresco.repo.node.NodeServicePolicies  
beforeAddAspect
beforeArchiveNode
beforeCreateNode
beforeCreateStore
beforeDeleteAssociation
beforeDeleteChildAssociation
beforeDeleteNode
beforeMoveNode
beforeRemoveAspect
beforeSetNodeType
beforeUpdateNode
onAddAspect
onCreateAssociation
onCreateChildAssociation
onCreateNode
onCreateStore
onDeleteAssociation
onDeleteChildAssociation
onDeleteNode
onMoveNode
onRemoveAspect
onSetNodeType
onUpdateNode
onUpdateProperties
Related