BlueStar
BlueStar

Reputation: 411

Is it possible to inherit cm:folder properties to its content in alfresco?

I have the following in my model.xml

<type name="abc:Policy">
          <title>abc Policy</title>
          <parent>cm:folder</parent>
          <archive>true</archive>

          <mandatory-aspects>
              <aspect>abc:policyProperties</aspect>
          </mandatory-aspects>
</type>

abc:policyProperties has the following.

  <aspect name="abc:policytProperties">
        <title>abc Policy Properties</title>
        <properties>
            <property name="abc:dated">
                <title>Dated</title>
                <type>d:date</type>
            </property>
        </properties>
  </aspect>

A user can upload a document to the abc:Policy folder. But there is no reference to that document currently in the model. How to make it possible for any document within this folder to inherit abc:dated and display it within its properties in Alfresco-share?

Upvotes: 1

Views: 1329

Answers (2)

Jeff Potts
Jeff Potts

Reputation: 10538

It sounds like what you want to do is have a document inherit a property value from the same-named property on the document's parent folder.

One way to do this would be to write a folder rule in JavaScript that reads the property and sets it on a document. You can configure the rule to do that when the document is created or when it is updated.

Here's a quick example that does this with the out-of-the-box cm:title property:

var title = document.parent.properties['cm:title'];
if (title != undefined) {
    document.properties['cm:title'] = title;
    document.save();
}

You can put that script in a file called "inherit-title.js" under Data Dictionary/Scripts, then configure your rule to execute the script. Any time a new object is created in that folder it will get the current title.

You can modify this to work with your content model.

Note that unless you configure the rule to work on updates, the value on the child will never be updated. So if the title changes in the folder it will not change in its children. And if a child is changed it will not pull the latest value from the parent. You could get that to happen through some rule config and script tweaks, but be mindful of the performance cost.

If you wanted to make this happen more universally, i.e., without setting this up as rules on individual folders, you could write a behavior to do it (tutorial).

Upvotes: 5

Sachin  Mesare
Sachin Mesare

Reputation: 175

If you refer to alfresco content model definitions contentModel.xml

you will find that, cm:folder has default child association cm:contains for the type sys:base. So you are able to add node of type that extends sys:base.

Each document added to your folder abc:Policy goes as a child. And the aspect is applied to parent i.e. abc:Policy. So abc:dated is a property of abc:Policy and not of the document.

One thing you can do is, define one more type that extends cm:content and add is as a child association to your abc:Policy also apply the aspect to it, then you can get the abc:dated as a property of your document

Upvotes: 0

Related Questions