<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to Programmatically Create a New Folder and Relocate a File Into It in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31851#M13508</link>
    <description>&lt;P&gt;Thank you for your help, it is really appriciated.&lt;/P&gt;&lt;P&gt;Yes, this is one-time deal.&lt;/P&gt;&lt;P&gt;Can we alter the meta deta attribute values of the moving file as well with this technique?&lt;/P&gt;&lt;P&gt;If you dont mind can you please write a sample JSON rule which is going to meet my requirment?&lt;/P&gt;&lt;P&gt;In case there is any helpful article which descrites how to write JSON rule then please share it.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2019 21:43:35 GMT</pubDate>
    <dc:creator>MuhammadBashir</dc:creator>
    <dc:date>2019-10-10T21:43:35Z</dc:date>
    <item>
      <title>How to Programmatically Create a New Folder and Relocate a File Into It</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31849#M13506</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I need some help regarding my following query.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Problem Statement:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Currently around &lt;U&gt;1500 files&lt;/U&gt; are &lt;U&gt;wrongly placed&lt;/U&gt; in &lt;U&gt;255 folders&lt;/U&gt; with some &lt;U&gt;misleading value of the metadata attributes&lt;/U&gt; as well.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Target State:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Relocate&lt;/U&gt; these &lt;U&gt;1500 files&lt;/U&gt; FROM their &lt;U&gt;existing 255 folders&lt;/U&gt; TO &lt;U&gt;255 NEWLY CREATED folders&lt;/U&gt; and &lt;U&gt;update the value of some of the medatadata attributes&lt;/U&gt; as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Query&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Is there any programatic way to achieve this target state by using Alfresco out of the box tools or programing interface?&lt;/P&gt;&lt;P&gt;&lt;U&gt;Possible Options&lt;/U&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Writing SQL (Create, Update, Delete) to directly update Aflresco database (Create New Folder, Relocate Files, Update Metadata).&lt;/LI&gt;&lt;LI&gt;Write a small program or utility which will call Alfresco APIs (If there are any) to acheive the target state.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Please dont hesitate to ask in case you need any further detail. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 01:28:21 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31849#M13506</guid>
      <dc:creator>MuhammadBashir</dc:creator>
      <dc:date>2019-10-08T01:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to Programmatically Create a New Folder and Relocate a File Into It</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31850#M13507</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 17:02:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31850#M13507</guid>
      <dc:creator>jljwoznica</dc:creator>
      <dc:date>2019-10-10T17:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Programmatically Create a New Folder and Relocate a File Into It</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31851#M13508</link>
      <description>&lt;P&gt;Thank you for your help, it is really appriciated.&lt;/P&gt;&lt;P&gt;Yes, this is one-time deal.&lt;/P&gt;&lt;P&gt;Can we alter the meta deta attribute values of the moving file as well with this technique?&lt;/P&gt;&lt;P&gt;If you dont mind can you please write a sample JSON rule which is going to meet my requirment?&lt;/P&gt;&lt;P&gt;In case there is any helpful article which descrites how to write JSON rule then please share it.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 21:43:35 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31851#M13508</guid>
      <dc:creator>MuhammadBashir</dc:creator>
      <dc:date>2019-10-10T21:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Programmatically Create a New Folder and Relocate a File Into It</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31852#M13509</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;// 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();
}&lt;/PRE&gt;&lt;P&gt;Save this code in a file script.js and upload it in the Alfresco space:&lt;/P&gt;&lt;P&gt;Company Home &amp;gt; Dictionary &amp;gt; Scripts.&lt;/P&gt;&lt;P&gt;Follow this instructions to create a rule in the parent&amp;nbsp; of the old folders:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.alfresco.com/5.2/tasks/library-folder-rules-define-create.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://docs.alfresco.com/5.2/tasks/library-folder-rules-define-create.html&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Once you have the rule execute it from &lt;SPAN class="ph uicontrol"&gt;Manage Rules page&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Of course here we are doing some assumptions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;All the old spaces are have the same parent.&lt;/LI&gt;&lt;LI&gt;The files are placed in the old spaces not in any subspace.&lt;/LI&gt;&lt;LI&gt;Both old and new root folder are placed in Company Home.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2019 17:32:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-programmatically-create-a-new-folder-and-relocate-a-file/m-p/31852#M13509</guid>
      <dc:creator>roberto_gamiz</dc:creator>
      <dc:date>2019-11-19T17:32:08Z</dc:date>
    </item>
  </channel>
</rss>

