cancel
Showing results for 
Search instead for 
Did you mean: 

Why can't I have more writeable variables?

erangaj
Champ in-the-making
Champ in-the-making
I am using v2.1.

The following syntax throws an exception. It expects an other tag inside <script>.

<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
  <script>
    // some alfresco javascript
  </script>
</action>

But the following syntax works.

<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
  <script>
     <expression>
       // some alfresco javascript
     </expression>
     <variable name="passedInValue" access="read"/>
     <variable name="passedOutValue" access="write"/>
  </script>
</action>

But I can have only one writeable variable. Otherwise it throws an exception.

In lot of examples I saw the first syntax and the second one (with multiple writeable variable) were used. But why can't I use that syntax.

adhoc_processdefinition.xml which uses the first syntax works without any problem But my custom process definitions does not work Smiley Sad.

Thanks & Regards,
Eranga
3 REPLIES 3

davidc
Star Contributor
Star Contributor
The first form is definitely valid - as you it's used in the out-of-the-box workflows.  What script do you have in your <script> tags?  You may need to wrap it in a CDATA block.

You can only have one writable variable because that's the way it is right now.  We can support more, but it requires a slight change to how we've integrated the javascript engine.

erangaj
Champ in-the-making
Champ in-the-making
I used the following process definition. The first JS works. But the second one throws an exception. If the second one is also has <expression> tags it won't throw an exception.

<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="http://jbpm.org/3/jpdl" name="bmd:issueCertificateWorkflow">
   <swimlane name="initiator" />
   <swimlane name="reviewer">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <pooledactors>#{people.getGroup('GROUP_' + userhome.properties['cm:name'] + '_reviewer')}</pooledactors>
      </assignment>
   </swimlane>
   <swimlane name="printer">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <pooledactors>#{people.getGroup('GROUP_' + userhome.properties['cm:name'] + '_printer')}</pooledactors>
      </assignment>
   </swimlane>
   <start-state name="start">
      <task name="bmd:submitBMDTask" swimlane="initiator"/>
      <transition name="Review" to="review">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <!– variable name="bmd_serialNo" access="write"/ –>
               <expression>
                  var bmdutility = actions.create("bmd-utility");
                  bmdutility.parameters.dsid=userhome.properties['cm:name'];
                  bmdutility.parameters.dsname=userhome.properties['cm:name'];
                  bmdutility.parameters.action="insert";
                  bmdutility.execute(bpm_package);
               </expression>
            </script>
         </action>
      </transition>
   </start-state>
   <task-node name="review">
      <task name="bmd:reviewBMDTask" swimlane="reviewer">
         <event type="task-create">
             <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                      logger.log(bpm_package.properties["{http://www.example.com/model/bmd}bmdkey"]);
               </script>
             </action>
         </event>
      </task>
      <transition name="Approve" to="print"></transition>
      <transition name="Reject" to="rejected"></transition>
   </task-node>
   <task-node name="print">
      <task name="bmd:printBMDTask" swimlane="printer"/>
      <transition name="Printed" to="completed"></transition>
   </task-node>
   <task-node name="completed">
      <task name="bmd:completedBMDTask" swimlane="initiator"/>
      <transition name="Done" to="end"/>
   </task-node>
   <task-node name="rejected">
      <task name="bmd:rejectedBMDTask" swimlane="initiator"/>
      <transition name="Resubmit" to="review"></transition>
      <transition name="Discard" to="end"></transition>
   </task-node>
   <end-state name="end"></end-state>
</process-definition>


……………..
……………………..
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: org.alfresco.service.cmr.workflow.WorkflowException: Failed to deploy workflow definition
        at org.alfresco.repo.workflow.jbpm.JBPMEngine.deployDefinition(JBPMEngine.java:287)
        at org.alfresco.repo.workflow.WorkflowServiceImpl.deployDefinition(WorkflowServiceImpl.java:107)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy43.deployDefinition(Unknown Source)
        at org.alfresco.repo.workflow.WorkflowDeployer.deploy(WorkflowDeployer.java:210)
        … 35 more
Caused by: org.jbpm.JbpmException: Failed to parse process definition from jBPM xml stream
        at org.alfresco.repo.workflow.jbpm.JBPMEngine.compileProcessDefinition(JBPMEngine.java:1641)
        at org.alfresco.repo.workflow.jbpm.JBPMEngine$1.doInJbpm(JBPMEngine.java:274)
        at org.springmodules.workflow.jbpm31.JbpmTemplate$1.doInHibernate(JbpmTemplate.java:87)
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:333)
        at org.springmodules.workflow.jbpm31.JbpmTemplate.execute(JbpmTemplate.java:80)
        at org.alfresco.repo.workflow.jbpm.JBPMEngine.deployDefinition(JBPMEngine.java:269)
        … 56 more
Caused by: org.jbpm.jpdl.JpdlException: [[ERROR] line 37: cvc-complex-type.2.3: Element 'script' cannot have character [children], because the type's content type is element-only., [WARNING] swimlane 'initiator' does not have an assignment]
        at org.jbpm.jpdl.xml.JpdlXmlReader.readProcessDefinition(JpdlXmlReader.java:173)
        at org.alfresco.repo.workflow.jbpm.JBPMEngine.compileProcessDefinition(JBPMEngine.java:1636)
        … 62 more
10:42:53,381 ERROR [[Catalina].[localhost].[/alfresco]] Exception sending context initialized event to listener instance of class org.alfresco.web.app.ContextListener
org.alfresco.error.AlfrescoRuntimeException: Workflow deployment failed
        at org.alfresco.repo.workflow.WorkflowDeployer.deploy(WorkflowDeployer.java:224)
        at org.alfresco.repo.workflow.WorkflowDeployer.onBootstrap(WorkflowDeployer.java:235)
        at org.alfresco.util.AbstractLifecycleBean.onApplicationEvent(AbstractLifecycleBean.java:62)
……………………..
…………………….

davidc
Star Contributor
Star Contributor
The namespace of your jBPM process definition is incorrect.  It should be

<process-definition xmlns="urn:jbpm.org:jpdl-3.2">

See http://docs.jboss.com/jbpm/v3/userguide/jpdl.html#d0e5138