cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript to move content to a folder

davix
Champ in-the-making
Champ in-the-making
Hi,

I've written JavaScript to move content to a folder like this.

var activeFolder = companyhome.childByNamePath("Content_Expiry");var archivedFolder = companyhome.childByNamePath("Content_Expiry/ExpiredContent");if(activeFolder != null){var i=0;activeChildren = activeFolder.children;activeTotal = activeChildren.length;for(i=0; i<activeTotal;i++){child = activeChildren[i];child.move(archivedFolder);}}‍‍‍‍‍‍‍‍‍‍‍‍‍
I have a project called Content_Expiry under Web Projects. And I'm trying to move the content to a folder called ExpiredContent in the same project. However the above JavaScript doesn't work. Am I giving the paths wrong here –> companyhome.childByNamePath("Content_Expiry");

Please let me know, thanks!
7 REPLIES 7

jpotts
World-Class Innovator
World-Class Innovator
It sounds like you are moving nodes that reside in a Web Project, which means you are working with the AVM store. I don't think you can get to an AVM node using companyhome's childByNamePath function (I could be wrong).

Have you taken a look at the AVM JavaScript API and the avm.lookupNode(path) function? Here's the wiki page with the doc:
http://wiki.alfresco.com/wiki/3.4_JavaScript_API#AVM_API

Jeff

davix
Champ in-the-making
Champ in-the-making
Thanks Jeff, I've looked up what you suggested.

So what I did was –
var fullcurrentpath = "/www/avm_webapps/ROOT/Folder1";var fullarchivepath = "/www/avm_webapps/ROOT/Folder2";var stores = avm.stores;var currentFolder = avm.lookupNode(stores[3].id + ":" + fullcurrentpath);var archivedFolder = avm.lookupNode(stores[3].id +  ":" + fullarchivepath);if(currentFolder != null){var i=0;activeChildren = currentFolder.children;activeTotal = activeChildren.length;for(i=0; i<activeTotal;i++){child = activeChildren[i];child.move(archivedFolder);}}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
This works!  Smiley Happy

jpotts
World-Class Innovator
World-Class Innovator
Excellent! Glad you got it working. Thanks for marking the thread resolved and for the useful rating.

Jeff

davix
Champ in-the-making
Champ in-the-making
Hi,

I have one additional requirement. The JS that I wrote moves all the content in the folder. Suppose there are sub folders like Folder1, Folder2, Folder3, etc and I don't want to move say Folder1. I tried as show below, but it doesn't work.

var currentFolder = avm.lookupNode("ContentExpiry–admin:/www/avm_webapps/ROOT");var archivedFolder = avm.lookupNode("ExpiredContent–admin:/www/avm_webapps/ROOT/Folder1");if(currentFolder != null){var i=0;activeChildren = currentFolder.children;activeTotal = activeChildren.length;for(i=0; i<activeTotal;i++){child = activeChildren[i];if(child != 'Folder1'){child.move(archivedFolder);}}}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Is this part wrong? – >if(child != 'Folder1'), please let me know, thanks!

ddanninger
Champ in-the-making
Champ in-the-making
i think if you wanna check for the name "Folder1" you should work with that:

// …child = activeChildren[i];childName = child.name;if(childName != 'Folder1'){child.move(archivedFolder);}// …‍‍‍‍‍‍‍‍‍‍‍‍‍‍

davix
Champ in-the-making
Champ in-the-making
Thanks! This works perfectly for me. Smiley Happy

rajshree11
Champ in-the-making
Champ in-the-making
It sounds like you are moving nodes that reside in a Web Project, which means you are working with the AVM store. I don't think you can get to an AVM node using companyhome's childByNamePath function (I could be wrong).

Have you taken a look at the AVM JavaScript API and the avm.lookupNode(path) function? Here's the wiki page with the doc:
http://wiki.alfresco.com/wiki/3.4_JavaScript_API#AVM_API

Jeff
Hi Jeff,
I have a similar requirement …….I have to move the contents from folder1 to folder2 on basic of key "published folder", so that a third application can access folder2…….can u please help