1

I have created a js file to create folders when creating an event in Alfresco. But the problem is, when I create an event on the Alfresco site, it will automatically create a folder in a shared folder. That's a problem because when updating an existing event it creates a new folder without removing the existing folder. Also, when I delete an event it will not delete the corresponding folder.

How can I solve this problem?

Here is my code to create a new folder when an item is created:

// create a new folder in the same space
var folderNode = space.createFolder(document.properties["ia:whatEvent"]);

// copy the doc into the newly created folder node
//var copy = document.copy(folderNode);

// move the folder node to companyhome
var objDestFolder = companyhome.childByNamePath("Shared/SECRETARY/COMMISSION_PAPER_RECEIVED");
folderNode.move(objDestFolder);

1 Answers1

1

If you wanted to create folder in the site than you need to specify the parent folder object where the new folder/document will get created.

like docLibContainer.createFolder for this docLibContainer is parent folder object.

In your case space is parent folder object.

Please try in this example docLibContainer will create a folder of name document.properties["ia:whatEvent"] in Document Library Folder.

 var site = document.getSiteShortName();
    var docLibContainer = siteService.getSite(site).getContainer("documentLibrary");

    if(docLibContainer){
        // create a new folder in the same space
        var folderNode = docLibContainer.createFolder(document.properties["ia:whatEvent"]);

        // copy the doc into the newly created folder node
        //var copy = document.copy(folderNode);

        // move the folder node to companyhome
        var objDestFolder = companyhome.childByNamePath("Shared/SECRETARY/COMMISSION_PAPER_RECEIVED");
        folderNode.move(objDestFolder);
    }else{
            // create a new folder in the same space
        var folderNode = space.createFolder(document.properties["ia:whatEvent"]);

        // copy the doc into the newly created folder node
        //var copy = document.copy(folderNode);

        // move the folder node to companyhome
        var objDestFolder = companyhome.childByNamePath("Shared/SECRETARY/COMMISSION_PAPER_RECEIVED");
        folderNode.move(objDestFolder);
    }
Vikash Patel
  • 1,328
  • 9
  • 28