Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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);

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

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