cancel
Showing results for 
Search instead for 
Did you mean: 

Question about javascript and assocs.

katootje
Champ in-the-making
Champ in-the-making
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
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
If you change this code:

        for (var propName in node.properties) {
            log +=  "child " + propName + "=" +  node.properties[propName] + "\r\n";
         }
to this does it show the nodes on the end of the assocs?

log +=  "child " + node.name + "\r\n";

Thanks,

Kevin

katootje
Champ in-the-making
Champ in-the-making
Kevin,

I then get 'child undefined' in the output file. The associated document does have a name and a whole lot of other properties. 

Evelien

katootje
Champ in-the-making
Champ in-the-making
This worked:

for (var assocname in document.assocs) {
    log +=  "assoc " + assocname + "\r\n";
    for (assoc in document.assocs[assocname]) {
        log += "assoc child  " + assoc + "\r\n";
        log += "assoc name " + document.assocs[assocname][assoc].properties.name + "\r\n";
    }
}

Evelien

kevinr
Star Contributor
Star Contributor
I then get 'child undefined' in the output file. The associated document does have a name and a whole lot of other properties.

Sorry yes the code i typed had an error, doh. But you get the idea Smiley Happy

I can see retrieving the associations is working fine now from your other post.

Thanks,

Kevin