Call Us India :- +91 9925144200       US :- +1 (732) 927-5544       Email us : hello@contcentric.com

Blog

Jan 15

Create Folders and Sub-folders on Uploading a CSV File in Alfresco

A typical Document Management System use case in Alfresco would require creating multiple folders while implementing for the first time or any time in future as well. Those folders can be for each employee, branch or project in the organization. Creating them manually is a mundane, time-consuming and prone-to-error task. How if you can create these folders with a mere upload of a CSV file? Sounds interesting?

In this blog, we have provided you a code using which Alfresco developers would be able to set a mechanism for the users who would get the following functionality.

We need to have two folders, one in which we would upload the CSV and the other where the folders will be residing after auto-generation, let’s name it as target folder. We have considered that the auto-generated folder will be renamed as columnAvalue_comunBvalue (by using values in the adjoining columns in the same row of CSV). So, the CSV we upload in this case should have one row for each folder with two columns to be placed as folder names. The sub-folders will be fixed for any auto-generated folder (In this case we have named them child1…child6). You may amend the code as per the business requirements of your client.

Alfresco development related blog: Alfresco QCAD Integration for CAD Files Preview

Here are the steps to follow:

Step 1: For creating folders and sub-folders we need to write the script.

So first we create “csvUploadFolderCreation.js” file and put it in “Data Dictionary/Scripts”

var siteName = document.getSiteShortName();

var path = companyhome.childByNamePath("Sites/"+siteName+"/documentLibrary/Target");

var subFolders = ["child1","child2","child3","child4","child5","child6"];

var col1=null,col2=null;

if(!document.isContainer){

var fileContent = document.getContent();

var csvline = fileContent.split("\n");

var csvLineLength = csvline.length;

for (var i=1 ; i<csvline.length; i++){

var csv = csvline[i].split(";");

col0 = csv[0];

col1 = csv[1];

var folderName = col0+"_"+col1;

var parent = path.createFolder(folderName);

parent.properties["name"] = folderName;

createSubFolders(parent);

}

}

function createSubFolders(parent){

for(var i=0;i<subFolders.length;i++){

parent.createFolder(subFolders[i].toString());

}

}

Step 2: Create a folder (Csv Upload) in your site and go to the action “Manage Rules”.

Now create a new rule. Add other info wise requirment and goto to “Perform Action”, select execute script and select our custom script.

Step 3: Create folder “Target” Which Contains all the folders which are created from csv.

Step 4: Now upload the csv file in “CSV Upload” folder.

Sub-folder will be created in Target folder as per the csv data.

If you find any challenge in implementing the same, feel free to contact us.

Vidhi P

About The Author

Vidhi is involved in the ECM project development at ContCentric. She is an ACE501, Alfresco Certified Engineer.

Leave a reply

Your email address will not be published. Required fields are marked *