Skip to content

Instantly share code, notes, and snippets.

@flox1an
Created January 28, 2015 15:12
Show Gist options
  • Save flox1an/2a726224e23381fa41f9 to your computer and use it in GitHub Desktop.
Save flox1an/2a726224e23381fa41f9 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);
@jeremiebal
Copy link

Hi Florian.
In Alfresco One 5.1 i have this error :
org.springframework.extensions.webscripts.WebScriptException: 00180057 Wrapped Exception (with status template): 001815817 Failed to execute script 'Javascript Console Script': Invalid bean definition with name 'policyBehaviourFilter' defined in class path resource [alfresco/policy-context.xml]: Can only specify arguments for the getBean method when referring to a prototype bean definition

I'll try to fix it or another solution

Jérémie

Copy link

ghost commented Jun 19, 2017

This should work on Alfresco 5.x:

var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var cls = org.alfresco.repo.policy.BehaviourFilterImpl;

var behaviourFilters = ctx.getBeansOfType(cls);
var filter = null;
for (var i in behaviourFilters) {
	if (i === "policyBehaviourFilter") {
		filter = behaviourFilters[i];;
		break;
	}
}

print(filter);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment