cancel
Showing results for 
Search instead for 
Did you mean: 

Copying a data list to another Share site?

jynnyd
Champ in-the-making
Champ in-the-making
Hello,

I hope that I'm not repeating a question here but after hours of research I haven't found the answer to my question so I'm posting it here!

We would like to copy a data list to another Share site, or copy lists items to another data list but this doesn't seem to be working.

Could you tell me if this is possible at all?  If not, could we develop some way to do this?

Thanks in advance!

JynnyD
2 REPLIES 2

vamirr
Champ on-the-rise
Champ on-the-rise
You could do this with the import/export tools in Alfresco explorer.

Or

Here's a script that does it as well.   Put this in Company Home > Data Dictionary > Scripts

(From Explorer) Edit the source and destination site names and do a run action > execute script > copySiteAssets.js


It'll copy additional site assets like document library by editing the asset name variable appropriately.

copySiteAssets.js:
function processCommand(){
   try{
   logger.log("/*—————————————————————————–copySiteAssets.js");


   var sourceSiteShortName = "test-site-1";
   var destSiteShortName = "test-site-2";
   var assetName = "dataLists"

   var sourceSiteNode = siteService.getSite(sourceSiteShortName).node;   
   var destSiteNode = siteService.getSite(destSiteShortName).node;

   var sourceAssetNode;
   var destAssetNode;


   if(!(sourceSiteNode && destSiteNode)){
      logger.log("Source or Destination Site Nodes Not Found");
      return;
   }

   //Look to see if the asset exists under the source node…
   for(var i = 0; i < sourceSiteNode.children.length; i++){
      currentNode = sourceSiteNode.children[i];

      if(currentNode.properties["cm:name"] == assetName)
         sourceAssetNode= currentNode;
   }
   
   if(!sourceAssetNode){
      logger.log("Asset: " + assetName + " not found under source Site: " + sourceSiteShortName );
   }

   //Look to see if asset exists under the destination node
   for(var i = 0; i < destSiteNode.children.length; i++){
      currentNode =  destSiteNode.children[i];

      if(currentNode.properties["cm:name"] == assetName)
          destAssetNode= currentNode;
   }   
   
   //If asset doesn't exist already, create it.
   if(!destAssetNode){
      destSiteNode.createFolder(assetName);
   }

   //For each node under the asset's main folder, copy that to the destination.
      for(var i = 0; i < sourceAssetNode.children.length; i++){
      asset = sourceAssetNode.children[i];
      asset.copy(destAssetNode, true);
   }
   logger.log("/*—————————————————————————–copySiteAssets.js");
   }catch(err){logger.log(err);}
}

processCommand();


Note that I haven't tested this on anything other than Enterprise 3.4.4.   4.0 doesn't create all site asset folders immediately on site creation, that could cause a problem if you're using Alfresco 4.  Just make sure you have the datalist exposed in the site before running the script.

jynnyd
Champ in-the-making
Champ in-the-making
Thank you Vamirr!

This was exacly the answer I was looking for!

Have a nice day!