JavaScript to move content to a folder

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2011 05:48 AM
Hi,
I've written JavaScript to move content to a folder like this.
Please let me know, thanks!
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!
Labels:
- Labels:
-
Archive
7 REPLIES 7
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2011 06:10 PM
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
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

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2011 07:42 AM
Thanks Jeff, I've looked up what you suggested.
So what I did was –
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! 
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2011 10:16 AM
Excellent! Glad you got it working. Thanks for marking the thread resolved and for the useful rating.
Jeff
Jeff

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2011 04:32 AM
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.
Is this part wrong? – >if(child != 'Folder1'), please let me know, thanks!
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!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2011 11:20 AM
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);}// …

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2011 12:56 AM
Thanks! This works perfectly for me.


Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2012 01:27 PM
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).Hi Jeff,
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
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
