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.
Here are the steps to follow:
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
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 fileContent = document.getContent();
var csvline = fileContent.split("\n");
var csvLineLength = csvline.length;
for (var i=1 ; i 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