in Alfresco

Alfresco export users from one server to the other


Exporting users in alfresco can be a problem, there are multiple solutions for this like using alfrescos export tool. We just want to export users and some of the properties from one server to the other and we want it to work on any alfresco version.


Solution is fairly simple, lets create a script that will generate code that we are going to run on other server and recreate the users. (what?? (: ) Ok lets see the code:


var peopleCollection = search.luceneSearch("TYPE:\"{}person\" ");

var output = "";
for (var i = 0; i < peopleCollection.length; i++) {
 var pers = peopleCollection[i];

 output += (" if(people.getPerson('" +["cm:userName"] + "')==null){\n");
 output += (" user = people.createPerson('" +["cm:userName"] + "',
              '" +["cm:firstName"] + "',
              '" +["cm:lastName"] + "',
              '" +["cm:email"] + "',
              'password' ,true);\n");

 if (["cm:organization"] != null)
     output += ("['cm:organization']='" 
                      +["cm:organization"] + "';\n");

 if (["cm:jobtitle"] != null)
     output += ("['cm:jobtitle']='" 
                 +["cm:jobtitle"] + "';\n");

 if (["cm:location"] != null)
     output += ("['cm:location']='" 
        +["cm:location"] + "';\n");

     output += (";\n");
     output += ("}\n");

var article = companyhome.createNode("createUsers.js", "cm:content");
article.content = output;;

What does this do?

It creates a file createUsers.js,  when this file is executed alfresco will create users with properties in this case first and last name, email, organization, jobtitle and location. You can add other if you desire.

Lets see the createUsers.js

 user = people.createPerson('prvoslav','Prvoslav', 'Savic','',                              'password' ,true);['cm:organization']='AlfrescoBlog';['cm:jobtitle']='Blogger';['cm:location']='Serbia';;

Execute createUsers.js script in other alfresco and you will get the same users, with same properties on the other server.


Here we have shown you how to “copy” users from one server to the other without using the alfresco export tool.


Don't be shellfish...Tweet about this on TwitterShare on LinkedInShare on Google+Share on RedditShare on Facebook

Was this helpful ?

  1. Hi,

    Is this script going to do the job if I’m going to try exporting Alfresco 4.x Users and import them into Alfresco 5.2.0d


    • Hi,
      script should be ok. In case it is not minor adjustments should be added.

      You can try the export script out it can not do any harm to your system. When you try import script ( import script is generated after export script finishes) just add throw “Rollback”; in the end.

      Cheers .