05-27-2010 09:27 AM
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="onUpdateNode_SetNewNummer" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
<property name="policyName">
<value>{http://www.alfresco.org}onUpdateNode</value>
</property>
<property name="className">
<value>{http://www.mymodels.com/model/content/1.0}newNumber</value>
</property>
<property name="behaviour">
<bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
<property name="location">
<bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
<constructor-arg>
<value>alfresco/module/company/context/scripts/onUpdateNode_SetNewNummer.js</value>
</constructor-arg>
</bean>
</property>
</bean>
</property>
</bean>
</beans>
logger.log("LCM onUpdateNode_SetDocnumber has fired");
var scriptFailed = false;
// Have a look at the behaviour object that should have been passed
if (behaviour == null)
{
logger.log("LCM The behaviour object has not been set.");
scriptFailed = true;
}
// Check the name of the behaviour
if (behaviour.name == null && behaviour.name != "onUpdateNode")
{
logger.log("LCM The behaviour name has not been set correctly.");
scriptFailed = true;
}
else
{
logger.log("LCM Behaviour name: " + behaviour.name);
}
// Check the arguments
if (behaviour.args == null)
{
logger.log("LCM The args have not been set.")
scriptFailed = true;
}
else
{
if (behaviour.args.length == 1)
{
var nodeRef = behaviour.args[0];
logger.log("LCM NodeRef: " + nodeRef.id);
if (nodeRef.hasAspect("{http://www.mymodels.se/model/content/1.0}documentNumber")) {
setDocumentId(nodeRef);
}
}
}
function setDocumentId(document) {
var CounterValue = 1;
var CurrentYear = new Date().getFullYear();
// Get the Diarie Counter file
var DiarieCounterFile = companyhome.childByNamePath(CurrentYear);
// Check if the "YEAR" file exists allready
if (DiarieCounterFile == null) {
// If it does not exist, create it
var fileNode = companyhome.createFile(CurrentYear);
// Set the content to 1 (Default CounterValue value)
fileNode.content = CounterValue;
} else {
// Add one to counter variable
CounterValue= (parseInt(DiarieCounterFile.content)+1);
// Set the content to the new counter value
DiarieCounterFile.content = CounterValue;
}
// Set up aspect.property value
var props = new Array(1);
props["my:documentNumber"] = CurrentYear + '-' + utils.pad(CounterValue, 4);
// Write the value to the document
document.addAspect("my:documentNumber", props);
}
06-20-2010 08:52 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.