Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglascrp/eef2ab7197fea613a77f593b7784aac8 to your computer and use it in GitHub Desktop.
Save douglascrp/eef2ab7197fea613a77f593b7784aac8 to your computer and use it in GitHub Desktop.
Change username for cm:owner cm:creator cm:modifier in Alfresco Javascript Console
var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var behaviourFilter = ctx.getBean("policyBehaviourFilter");
// -----------------------------------------------------------------
function findAndReplaceAttribute(query, attribute, value) {
nodes = search.luceneSearch(query);
for each(var node in nodes) {
logger.log("Changing property "+attribute+" from value '"+ node.properties[attribute]+"' of node " + node.nodeRef + " to value '"+value+"'");
behaviourFilter.disableBehaviour(node.nodeRef);
node.properties[attribute] = value;
node.save();
}
}
// -----------------------------------------------------------------
var oldUser = "oldusername", newUser = "newusername";
findAndReplaceAttribute("+@cm\\:modifier:" + oldUser, "cm:modifier", newUser);
findAndReplaceAttribute("+@cm\\:creator:" + oldUser, "cm:creator", newUser);
findAndReplaceAttribute("+@cm\\:owner:" + oldUser, "cm:owner", newUser);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment