cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic property

mike38
Champ on-the-rise
Champ on-the-rise
Hello,

I would like to define an "automatic" property, that is a property which is automatically valued at the creation of the object, for example by calling some webscript. One example would be an identifier managed by the system.

I want to put this property in an aspect, and when an object whose type references this aspect is created, or when the aspect is added to the object, a value is fetched and set to the property, which would be read-only if possible. It is some kind of "dynamic" default value, a default value which is not hard-coded in the model but obtained through the webscript.

I know how to implement the webscript, what I don't understand is how to use the webscript to automatically fill the property.

It would also be better, I think, if this could be achieved on the repository side.

How can I do that ?

Thank you.
Mike
2 REPLIES 2

steven_okennedy
Star Contributor
Star Contributor
Hi Mike,

Normally you would not use a webscript for this as it's not an API external to Alfresco you're looking to expose, but a function you want to happen inside Alfresco in response to an event happening within the system.

The mechanisms that Alfresco provides that best match this type of requirement are Rules and Behaviours.  Typically you use rules to trigger actions that need to happen in specific places within the system (e.g. within sites or folders) and you use Behaviours when you want your fucntion to apply globally across the system regardless of where it is.  Both mechanisms can be filtered so that they only happen in response to certain events, and/or to content with certain properties (e.g. types, aspects etc).

Rules have 3 types of event you can attach to - on creation, on update or on delete (or on a combination of all 3).  Behaviours are linked to Alfresco Policies which are key events that the Alfresco core services publish, e.g. onCreateNodePolicy, onMoveNodePolicy, BeforeDeleteNodePolicy, BeforeAddAspectPolicy etc.  There are a lot more.

I would suggest that Behaviours are the way to go in your case, as you can cater more easily for handling the manual addition of an aspect after node creation time.  Have a look at Jeff Potts' tutorials on creating Behaviours here http://ecmarchitect.com/alfresco-developer-series-tutorials/behaviors/tutorial/tutorial.html

If you feel that RUles/Actions will work better, he also has another tutorial on creating custom actions that can be used by Rules: http://ecmarchitect.com/alfresco-developer-series-tutorials/actions/tutorial/tutorial.html

Regards

Steven

mike38
Champ on-the-rise
Champ on-the-rise
Ok thank you Steven, I was misleaded. I think that Behaviours is what I need, yes.

The tutorial works well under SDK 2.1. It was a little hard for a beginner to make it work under SDK 2.2.0, even with the documentation (Upgrading a Repository AMP project from SDK 2.1.1 to 2.2.0) because they don't mention some files which are now referenced but did not exist in the tutorial (bootstrap-context.xml, …) but now it works.

Thank you!