使用javascript在alfresco datalist关联中添加多个文档

Adding more than one document in alfresco datalist association using javascript

本文关键字:添加 文档 关联 javascript alfresco datalist 使用      更新时间:2023-09-26

我是第一次去户外。我有一个使用datalist处理员工记录的自定义模型。如果要添加的记录是新的,我可以读取扫描的文件名,并使用javascript附加相关元数据和关联中的文件。从扫描器扫描的文件具有以下信息21420-victor mathew-HR-copy of id-10.pdf。

第一个值表示人员惟一id。我的问题是,当第二个文档被扫描时,我希望它作为附件添加到数据列表中,但我的脚本正在创建一个新记录。这是我的javascript:

var docname = document.properties["cm:name"];//获取文件名splitFile = docname.split("-");//拆分获取元数据

fileCustomerNo    = splitFile[0];   
fileCustomerName  = splitFile[1];
fileDept          = splitFile[2]; 
fileDocType       = splitFile[5];   

    var testList = companyhome.childByNamePath("Sites/Employee/dataLists/823bd590-cbb7-4ea2-b9af-964ab4f1023a"); 
    var testEntry = testList.createNode(null, "tq:employee");

        var query= "@tq'':fileCustomerNo:" + fileCustomerNo;                        
        var results = search.luceneSearch(query);           
        if(results !=null && results.length !=0)
        {
                var relatedarticles = companyhome.createNode("paymentDocs", "cm:content");
                relatedarticles.properties.content.write(document.properties.content);                  
                testEntry.createAssociation(relatedarticles, "tq:related" );                    
                relatedarticles.save();
        }else{

    testEntry.properties["tq:CustomerNo"] = fileCustomerNo; 
    testEntry.properties["tq:CustomerName"] = fileCustomerName; 
    testEntry.properties["tq:dept"] = fileDept;         
    testEntry.save();               
    var relatedarticle = companyhome.createNode("paymentDocs", "cm:content");       
    relatedarticle.properties["cm:name"] = docname;
    relatedarticle.properties.content.write(document.properties.content);       
    testEntry.createAssociation(relatedarticle, "tq:related");
    relatedarticle.save();
    }

有人帮助我如何添加一个新的文档到现有的关联,就像我可以点击编辑和浏览在alfresco和添加文档的方式。

如果在内容模型中定义的关联上的多样性被设置为允许关联上的多个目标对象,那么您只需创建额外的关联。例如,下面是一个内容模型的片段,它允许多个文档关联,因为"many"被设置为true:

<target>
    <class>sys:base</class>
    <mandatory>false</mandatory>
    <many>true</many>
</target>

如果"many"被设置为false,当您尝试创建额外的关联时,您将收到一个错误。