AnsweredAssumed Answered

Non-mandatory properties not instantiated in content objects in a custom model

Question asked by lw7415 on Nov 14, 2013
Latest reply on Nov 25, 2013 by yogeshpj
Hello all,

I discovered an Alfresco feature related to custom data modeling. I'm not sure if this is an intended feature. I am using Alfresco Community 4.2.e and Alfresco Enterprise 4.2.0.

1. Create a custom data model "my:model" including a new data type "my:datatype" that extends "cm:content" by adding a new property of type text "my:property". Package the new model in an AMP.

2. Create code that extends the Alfresco Share user interface to allow users to create and edit content objects of type "my:datatype". Package the interface extensions in an AMP.

3. Apply the AMPs to alfresco.war and share.war and restart Alfresco.

4. Create a new content object of type "my:datatype" using the Share user interface. Do not assign a value to the property "my:property".

5. Examine the new content object using the node browser. The property "my:property" appears and has no value.

6. Create a web script that creates a new content object of type "my:datatype" as follows

var node = userhome.createNode("My sample document", "my:document");

7. Execute the web script and examine the new content object using the node browser. The property "my:property" <strong>does not appear</strong>.

If you write scripts that reference an object of type "my:document" and property "my:property", the script will blow up with a 500 error because the expected property is not present. In my case, a web script fails with error 500 and "freemarker.core.InvalidReferenceException" because the expected property is not part of the object being investigated.

One way to prevent this from happening is to make the property mandatory in the data model. This is undesirable in many cases.

The solution I found to make sure the property is created with the object is to specify a blank default value in the data model and not make the property mandatory:

<property name="my:property">

When defined like this, scripts referencing this property will always find it and not throw an exception.

Is this "missing property" feature expected in Alfresco? If so, is this something that might be referenced in the documentation?