AnsweredAssumed Answered

Simple script called by behavior-context

Question asked by cristian on Aug 26, 2010
Latest reply on Aug 26, 2010 by cristian
I've got this script (onUpdateOrder.js) that works right in a rule's "Execute Script" action.
The goal is to update a custom cm:folder property with the sum of its children property, when a custom type ("my:item") is updated in the context folder.
var childrenList = space.children;
if (childrenList)
{
    for (var i = 0; i < childrenList.length; i++)
    {
        item = childrenList[i];
        itemPrice = item.properties["my:itemPrice"];
        total += itemPrice;
    }
    space.properties["my:itemsSum"] = total;
    space.save();
}
.. I tried to trigger this script in a behavior-context.xml:
    <bean id="onUpdateOrderNode" 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.alfresco.org/orders/content/1.0}item</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/extension/scripts/onUpdateOrder.js</value>
                        </constructor-arg>
                               </bean>
                        </property>
           </bean>
        </property>
    </bean>
..but "space" is undefined. How to get the correct context in this environment??

Outcomes