AnsweredAssumed Answered

Question about javascript and assocs.

Question asked by katootje on Jul 16, 2007
Latest reply on Jul 17, 2007 by kevinr
Hello,

In an attempt to figure out how to handle groups of documents I wanted to find the associations of a document using javascript. I can successfully make associations in the client but I can't seem find them with my script.

I've installed the stable alfresco 2.1 community release.
This is the type I defined:
customModel.xml
      <!– Definition of new Content Type: Press Release –>
      <type name="eb:Opdracht">
         <title>Opdracht</title>
         <parent>cm:content</parent>
         <properties>
            <property name="eb:OpdrachtId">
               <title>Opdracht id</title>
               <type>d:int</type>
            </property>
         </properties>
         <associations>
            <association name="eb:Image">
               <title>Plaatje</title>
               <target>
                  <class>cm:content</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
            <association name="eb:Bijlage">
               <title>Bijlage</title>
               <target>
                  <class>cm:content</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
         <mandatory-aspects>
            <aspect>cm:versionable</aspect>
         </mandatory-aspects>
      </type>

web-client-config-custom.xml
    <config evaluator="string-compare" condition="Content Wizards">
        <content-types>
            <type name="eb:Opdracht" />
        </content-types>
    </config>

    <config evaluator="node-type" condition="eb:Opdracht" >
        <property-sheet>
            <show-association name="eb:Image" />
            <show-association name="eb:Bijlage" />
        </property-sheet>

And this my javascript:
// log the docs that currently contain the word 'Alfresco' to a log file
var logFile = space.childByNamePath("ListProperties.txt");
if (logFile == null) {
   logFile = space.createFile("ListProperties.txt");
}

if (logFile != null) {
    var log = "";
    log += "document properties: \r\n";
    for (var propName in document.properties) {
        var propValue = document.properties[propName];
        log += propName + "=" + propValue + "\r\n";
    }

    log += "plaatjes\r\n";
    for (var node in document.assocs["eb:Image"]) {
        for (var propName in node.properties) {
            log +=  "child " + propName + "=" +  node.properties[propName] + "\r\n";
         }
     }

     log += "any?\r\n";
     for (var node in document.assocs) {
         for (var propName in node.properties) {
             log +=  "child " + propName + "=" +  node.properties[propName] + "\r\n";
        }
    }

    logFile.content += log;
}

When running the script in a run action on a document (with associations) I do get the properties of my document in the ListProperties.txt file, but no associations. Should you be able to find them this way? A hint would be welcome.

Thanks,
Evelien

Outcomes