AnsweredAssumed Answered

Adding attachments to datalists via javascript

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

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"
+"/st:"+search.ISO9075Encode("sites")
+"/cm:"+search.ISO9075Encode(CurrentSiteName)
+"/cm:"+search.ISO9075Encode("documentLibrary")
+"/cm:"+search.ISO9075Encode("03 Packages")
+"/cm:"+search.ISO9075Encode("03 PIP")
+"/cm:"+search.ISO9075Encode("PP002")
+"/cm:"+search.ISO9075Encode("DO")+"//*\"";
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="http://www.alfresco.org/model/dictionary/1.0">

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

   <!– Imports are required to allow references to definitions in other models –>  
   <imports>
        <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
     <!– Import Alfresco Data List Model Definitions –>
      <import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
   </imports>

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

   <!–      T Y P E   D E F I N I T I O N S      –>  
   <types>
     <!–   Data list defintions For this model go here –>
      <type name="docl:documentList">
       <title>Document List</title>
       <description>Document List</description>
       <parent>dl:dataListItem</parent>
       <properties>
         <property name="docl:docNo">
            <title>Document no</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
         </property>
         <property name="docl:version">
            <title>Version</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
         </property>         
      </properties>      

       <associations>   
         <association name="docl:document">
            <title>Document</title>
            <source>
              <mandatory>false</mandatory>
              <many>true</many>
            </source>
            <target>
              <class>cm:content</class>
              <mandatory>false</mandatory>
              <many>true</many>
            </target>
         </association>
       </associations>
     </type>
   </types>    
</model>

Outcomes