AnsweredAssumed Answered

Transactions for Javascript behaviours

Question asked by loftux Moderator on Aug 30, 2010
I've been struggling with javascript based behaviours (version 3.3g). Once you have more than one, you will end up with transactions that crash when you do stuff from Share like Check out/in, and you get rollbacks.
Just a sample of one of the behaviour configs

   <bean id="onUpdateNode_AddTags" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
               <property name="policyName">
                       <value>{http://www.alfresco.org}onUpdateProperties</value>
               </property>
               <property name="className">
                       <value>{http://www.syvab.se/model/content/1.0}doc</value>
               </property>
               <property name="behaviour">
                       <bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
                        <property name="notificationFrequency">
                           <value>FIRST_EVENT</value>
                        </property>
                               <property name="location">
                                       <bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
                                               <constructor-arg>
                                                       <value>alfresco/module/syvab/context/scripts/onUpdateProperties_AddTags.js</value>
                                               </constructor-arg>
                                       </bean>
                               </property>
                       </bean>
               </property>
       </bean>
I've tried both with TRANSACTION_COMMIT, FIRST_EVENT. To me, the most logical seems to be that the event that fired my behaviour would run complete whne I'm using TRANSACTION_COMMIT, but that is not always the case. So if I'm updating the node (in the case above, adding tags), it may interfere with the original transaction, and a roll-back.
Another case is onAddAspect. I have a document ID aspect that creates an id for the document. But I dont want that to be added/updated on a working copy. But the event fires on the working copy (the aspect is added to the working copy), so I add code not to do anything on a working copy. But just the event firing may cause a rollback, even if I dont do anything on the node.

I understand this is vague for now. I just want to know if anyone has experience of using javascipt based behaviours, and if they do work.
I can probably submit test cases and scripts, but before I do (and it will take some time to create), I'm looking for feedback.
Is the only way to use java behaviours? or can I call execute script method that truly runs when transaction has completed.

Outcomes