AnsweredAssumed Answered

Adding attachments to datalists via javascript

Question asked by efvrvo on Aug 10, 2011
Latest reply on Aug 22, 2011 by efvrvo

I have created a javascript that I will be using to create a document register for me for a specific site. The idea is to run the script and it then populates a datalist with information about the documents in a folder in the library. So far the script works well  but I would also like to add the documents that I query in the datalist as an attachment. I have no idea how to do this using javascript (manual method is obviously very simple). I have tried various methods but with no results. Could anyone assist me with this.

This is my script with my last attempt to set the attachement
var displayPaths = document.displayPath.split("/");
var CurrentSiteName = displayPaths[3];

var query = "+PATH:\"/app:company_home"
+"/cm:"+search.ISO9075Encode("03 Packages")
+"/cm:"+search.ISO9075Encode("03 PIP")
var docs = search.luceneSearch(query);

for (var i=0; i<docs.length; i++)
    if (docs[i].isContainer == false)
        var documentPath = docs[i].displayPath.split("/");
        var documentLocation = "";
        var associations = docs[i].nodeRef;

        for (var j=0; j<documentPath.length; j++)
             documentLocation += documentPath[j] +"/";
        documentLocation += docs[i].name;

        var props = new Array(3);       
        props["docl:docNo"] = docs[i].name;
        props["docl:version"] = docs[i].properties["cm:versionLabel"];
        props["docl:document"] = docs[i].createAssociation( associations,"docl:document");

        var docName = "DocList_" + i;
        var doclist = space.createNode(docName, "docl:documentList",props);
        //doclist.createAssociation( associations,"docl:document");

This is my data model of the datalist (very simple for now)
<?xml version="1.0" encoding="UTF-8"?>

<!– Definition of new Model –>

<model name="docl:doclDatalist" xmlns="">

   <!– Optional meta-data about the model –>  
   <description>Custom Bhukka datalist</description>
   <author>Eugene vRvOudtshoorn</author>

   <!– Imports are required to allow references to definitions in other models –>  
        <!– Import Alfresco Dictionary Definitions –>
      <import uri="" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="" prefix="cm"/>
     <!– Import Alfresco Data List Model Definitions –>
      <import uri="" prefix="dl"/>

   <!– Introduction of new namespaces defined by this model –>  
       <namespace uri="" prefix="docl"/>

   <!–      T Y P E   D E F I N I T I O N S      –>  
     <!–   Data list defintions For this model go here –>
      <type name="docl:documentList">
       <title>Document List</title>
       <description>Document List</description>
         <property name="docl:docNo">
            <title>Document no</title>
         <property name="docl:version">

         <association name="docl:document">