简体   繁体   English

使用JavaScript在露天数据列表关联中添加多个文档

[英]Adding more than one document in alfresco datalist association using javascript

I am new to alfresco. 我是露天的新手。 I have a custom model that handles employee records using datalist. 我有一个使用数据列表处理员工记录的自定义模型。 If the record to be added is new, i can read the file name scanned and attach the related metadat and the file in an association using javascript. 如果要添加的记录是新记录,我可以读取扫描的文件名,并使用javascript将相关的metadat和文件关联在一起。 The file scannned from the scanner has the following infomation 21420-victor mathew-HR-copy of id-10.pdf. 从扫描仪扫描的文件具有以下信息21420-victor mathew-HR-副本id-10.pdf。

The first value represents the staff unique id. 第一个值代表员工的唯一ID。 my problem is that when the second document is scanned, i want it added in the datalist as an attachment, but my script is creating a new record. 我的问题是,扫描第二个文档时,我希望将其作为附件添加到数据列表中,但是我的脚本正在创建新记录。 this is my javascript: 这是我的javascript:

var docname = document.properties["cm:name"]; var docname = document.properties [“ cm:name”]; // get the name of the file splitFile = docname.split("-"); //获取文件名称splitFile = docname.split(“-”); // split to get metadata //拆分以获取元数据

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();
    }

Someone help me on how to add a new document to an existing association just like the way i can click edit and browse within alfresco and add the document. 有人帮助我如何将新文档添加到现有关联中,就像我可以在露天环境中单击“编辑和浏览”并添加文档的方式一样。

If the multiplicity on the association as defined in the content model is set to allow multiple target objects on the association, then you simply create the additional association. 如果将内容模型中定义的关联的多重性设置为允许关联上有多个目标对象,则只需创建其他关联即可。 For example, here is a snippet from a content model which would allow multiple documents to be associated because "many" is set to true: 例如,这是内容模型的一个片段,由于“ many”设置为true,因此该片段将允许关联多个文档:

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

If "many" were set to false, you would receive an error when you tried to create the additional association. 如果将“ many”设置为false,则在尝试创建其他关联时会收到错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM