10-07-2019 09:28 PM
Hi Team,
I need some help regarding my following query.
Problem Statement:
Currently around 1500 files are wrongly placed in 255 folders with some misleading value of the metadata attributes as well.
Target State:
Relocate these 1500 files FROM their existing 255 folders TO 255 NEWLY CREATED folders and update the value of some of the medatadata attributes as well.
Query
Is there any programatic way to achieve this target state by using Alfresco out of the box tools or programing interface?
Possible Options
Please dont hesitate to ask in case you need any further detail. Thanks.
10-10-2019 01:02 PM
Is this a one-time deal or something that you will be doing more than that? If you have access to the Share interface, you can write JSON to do this and then associate a rule with the parent folder of the original 255 folders and then run the rule to create the folders and move the files into them. Not sure if this would work, but it can be done.
10-10-2019 05:43 PM
Thank you for your help, it is really appriciated.
Yes, this is one-time deal.
Can we alter the meta deta attribute values of the moving file as well with this technique?
If you dont mind can you please write a sample JSON rule which is going to meet my requirment?
In case there is any helpful article which descrites how to write JSON rule then please share it.
11-19-2019 12:32 PM
Hello,
Using out of the box tools you could create a JavaScript and executing it via a rule in the parent of the existing folders. Here are a very simple approach:
// this is the root of the target var targetRoot = companyhome.childByNamePath("Venzia"); function getTargetName(name) { // Here you have to add the logic to found the name of the correct space. return 'Target ' + name; } function getTargetSpace(name) { var targetSpaceName = getTargetName(name); var newSpace = targetRoot.childByNamePath(targetSpaceName); if(newSpace === null) { newSpace = targetRoot.createFolder(targetSpaceName); } newSpace.properties.title = 'Creado'; newSpace.save(); return newSpace; } // document is the node in wich the rule is executing var currentSpace = document; var targetSpace = getTargetSpace(document.properties["cm:name"]); var files = currentSpace.getChildren(); for(var i in files){ var newFile = files[i].copy(targetSpace); logger.log(newFile.properties["cm:name"]); newFile.properties.title = 'Copiado'; newFile.save(); }
Save this code in a file script.js and upload it in the Alfresco space:
Company Home > Dictionary > Scripts.
Follow this instructions to create a rule in the parent of the old folders:
https://docs.alfresco.com/5.2/tasks/library-folder-rules-define-create.html.
Once you have the rule execute it from Manage Rules page.
Of course here we are doing some assumptions:
Regards
Explore our Alfresco products with the links below. Use labels to filter content by product module.