cancel
Showing results for 
Search instead for 
Did you mean: 

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

lw7415
Champ in-the-making
Champ in-the-making
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 "mySmiley Tongueroperty". 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 "mySmiley Tongueroperty".

5. Examine the new content object using the node browser. The property "mySmiley Tongueroperty" 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 "mySmiley Tongueroperty" <strong>does not appear</strong>.

If you write scripts that reference an object of type "my:document" and property "mySmiley Tongueroperty", 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">
<type>d:text</type>
<default></default>
</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?

Thanks,

Lw

1 REPLY 1

yogeshpj
Star Contributor
Star Contributor
Non-mandatory property would be initialized on content objects only when that property is set on content object explicitly.
Try to set blank value on property while creating/editing node.