AnsweredAssumed Answered

bi direction association

Question asked by etoropov on Jun 13, 2012
Latest reply on Jun 14, 2012 by amandaluniz_z
Is it possible to implement in Alfresco that would add to the content in the linked document newly created document is attached to the bound?
Ex.:
There is DocA. Create DocB (another type)
and add DocA as linked document to this DocB. How to do that new DocB would be automatically added to DocA?
Came up with the only option with javascript, which is hung as rule on the folder. while saviong or changing the document is searched for the attachment of the document and add the document as an association. Question - how to get to the name of the attached document (cm:name of attached document DocA(DocA_name))?

var insp = "@cm\\:name:DocA_name"; // it's hardcode. how to get DocA_name?

results = search.luceneSearch(insp);

for (var i = 0; i<results.length; i++){
    results[i].createAssociation(document, "sc:DocA4DocB" );
}
document.save();

model:
<type name="sc:DocA">
   <title>DocA</title>
   <parent>sc:document</parent>
   <properties>
          …
   </properties>
   <associations>
      <association name="sc:DocA4DocB">
         <title>DocA4DocB</title>
         <source>
            <mandatory>false</mandatory>
            <many>true</many>
         </source>
         <target>
            <class>cm:content</class>
            <mandatory>false</mandatory>
            <many>true</many>
         </target>
      </association>
   </associations>
</type>
<type name="sc:DocB">
   <title>DocB</title>
   <parent>sc:document</parent>
   <properties>
          …
   </properties>
   <associations>
      <association name="sc:DocB4DocA">
         <title>DocB4DocA</title>
         <source>
            <mandatory>false</mandatory>
            <many>true</many>
         </source>
         <target>
            <class>sc:DocA</class>
            <mandatory>false</mandatory>
            <many>true</many>
         </target>
      </association>
   </associations>
</type>

Outcomes