Javascript API – Cross Repository Copy

October 29, 2009

Recently I have been asked a few times for an example of how to copy content from the DM Alfresco repository into the AVM (WCM) repo, so I thought I would post a simple example using the JavaScript API to help people get started. It can be a little tricky getting the paths etc correct if you are new to Alfresco, so hopefully this will assist.

The 3.1 JavaSccript API wiki page shows the required parameters:

ScriptNode copy(ScriptNode source, ScriptNode destination, String name)

Download the example web script here.  This web script is based on some example code taken from the Alfresco Forge project – FlexSpaces which contains some great examples of WCM web scripts.

As you will see from the descriptor file, the required parameters are passed to the JavaScript via the following URL:

/crossRepoCopy?sourcenodeid={sourceAdmNodeId}&targetstoreid={targetAvmStoreId}&targetavmpath={targetAvmPath}

In a production environment, the required arguments will no doubt be generated programmatically, however for the purpose of a simple example, we will collect them manually.  Firstly, the sourcenodeid source i.e. the node id of the source item that you wish to copy from the DM repo.  Using the Node Browser for this example, navigate to the source file and copy the node.  It will look something like:

workspace://SpacesStore/371d692f-46e7-4ca8-84bb-81a032ac1363

Strip out the workspace://SpacesStore/ as the example script adds it as required so you are left with:

371d692f-46e7-4ca8-84bb-81a032ac1363

Next the targetAvmStoreId, so the store that we are going to copy to within the AVM. This is made up from the web project dns name and the sandbox user name. Use the node browser once again and look for the store-identifier property. In my example the store-identifier is:

demo--admin

Finally the targetAvmPath which is the folder path to the location within the sandbox of where the content item will be created. In my example I would like to copy the content to the root of my web application folder so I use:

/www/avm_webapps/ROOT

With all of the parameters in place, the final request string looks like:

http://localhost:8080/alfresco/service/crossRepoCopy?sourcenodeid=319a5e5c-e921-490d-ac75-12c0a678f92e&targetstoreid=demo--admin&targetavmpath=/www/avm_webapps/ROOT


If the copy was successful, you will see:

Result String - Node was copied
Result Code - true

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>