AnsweredAssumed Answered

onCreateAssociation behavior won't trigger

Question asked by abraxas on Aug 1, 2011
Latest reply on Mar 20, 2012 by jpotts
I've created a web-script behavior which should trigger when an association is created within
a document of my custom type. I can create associations without problems and they do get created
(I've double checked it using the node browser) but my behavior is never triggered, neither using onCreateAssociation
or onCreateNodeAssociation. Javascript debugger is up and logging enabled but (output from) my script doesn't show up
anywhere.

The webscript behavior looks something to this:



//should always show up in log
logger.log("ASSOC CREATED BEHAVIOR");

if (behaviour.args == null) {
  logger.log("No argumants have been set.");

} else {
        logger.log(behaviour.args[0].name);
  var docAssocs = behaviour.args[0].assocs;

        //define association type to be used
        var refAssocs = ["rmc:crossreference","rmc:supports",
            "rmc:versions","rmc:obsoletes",
            "rmc:supersedes","rmc:rendition"];
        var assocFileNames = [];

        for(var type = 0; type < refAssocs.length; type++){
            //if association type exits in node
            if(typeof docAssocs[refAssocs[type]] != "undefined"){
                var assocTypeList = docAssocs[refAssocs[type]];
                //iterate trough script nodes for association type
                for(var assoc = 0; assoc < assocTypeList.length; assoc++){
                    assocFileNames.push[assocTypeList[assoc].name];
                    logger.log(assocTypeList[assoc].name);
                }
            }
        }
  //behavior.args[0].properties["my:references"] = assocFileNames.join(",");
   logger.log(assocFileName);
  behaviour.args[0].save();
}

with a bean definition


<bean id="onMyAssociationCreate" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
        <property name="policyName">
            <value>{http://www.alfresco.org}onCreateAssociation</value>
        </property>
        <property name="className">
            <value>{http://www.alfresco.com/model/docs/1.0}myDoc</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/onMyAssociationCreate.js</value>
                        </constructor-arg>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

Outcomes