cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti, Alfresco, TimerStartEvent and Initiator

bprado
Champ in-the-making
Champ in-the-making
[posted on Alfresco forums but got no answer: http://forums.alfresco.com/forum/developer-discussions/workflow/timerstartevent-how-set-initiator-03... ]

Hi all,

I'm new to Alfresco and Activiti and after some digging was finally able to create, deploy and redeploy advanced custom workflows created with Activiti designer plug in for eclipse.
Unfortunately I had problems working with "TimerStartEvent". The TimerEventDefiniton worked as expected, and all my workflows were created "on time". My workflow, however, had incomplete properties, and "initiator" was missing. As a consequence, the tasks won't show in MyTasks (error in JavaScript) and tasks cannot be ended (error in log).
From what I could figure, If I could set the initiator of the workflow, everything would work as expected. Please notice that I tried setting activiti:initiator on StartEvent without success.

Any advice would be appreciated.

Alfresco version is 4.2.b (since 4.2.c is giving me errors when using custom workflows)

fcteste1.bpmn


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="fcteste1" name="fcteste1" isExecutable="true">
    <startEvent id="timerstartevent1" name="Timer start" activiti:initiator="bruno">
      <timerEventDefinition>
        <timeCycle>R5/PT1M</timeCycle>
      </timerEventDefinition>
    </startEvent>
    <userTask id="usertask1" name="Timer Task" activiti:assignee="bruno" activiti:candidateUsers="bruno,teste" activiti:formKey="wf:adhocTask">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>logger.log("Timed task created as expected");</activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow1" sourceRef="timerstartevent1" targetRef="usertask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_fcteste1">
    <bpmndi:BPMNPlane bpmnElement="fcteste1" id="BPMNPlane_fcteste1">
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="340.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="timerstartevent1" id="BPMNShape_timerstartevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="100.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="180.0" y="270.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="135.0" y="297.0"></omgdi:waypoint>
        <omgdi:waypoint x="180.0" y="297.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="285.0" y="297.0"></omgdi:waypoint>
        <omgdi:waypoint x="340.0" y="297.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

Log of error when trying to finish the task:


Mar 05, 2013 2:52:56 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: Exception while invoking TaskListener: 02053124 Mandatory task properties have not been provided! {http://www.alfresco.org/model/bpm/1.0}package

Javascript error on MyTasks:



["bpm_status"]),y=z.getData("owner"),v=c(z.getData("description")),l=c(q.initiator.firstName);var


Uncaught TypeError: Cannot read property 'firstName' of null


Description of workflow using workflow-console (initiator is null and shouldn't)


desc workflow activiti$840

definition: activiti$fcteste1
id: activiti$840
description: null
active: true
start date: Tue Mar 05 13:25:48 UTC 2013
end date: null
initiator: null
context: null
package: null

11 REPLIES 11

frederikherema1
Star Contributor
Star Contributor
The initiator-variable is set by alfresco WorklfowService when the process starts. if it's started using a timer, you should add the variable yourself by using, for example, a ExecutionListener on workflow-start. The code responsible for this:


// Add the initiator
            NodeRef initiator = getPersonNodeRef(currentUserName);
            if (initiator != null)
            {
                variables.put(WorkflowConstants.PROP_INITIATOR, nodeConverter.convertNode(initiator));
                // Also add the initiator home reference, if one exists
                NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
                if (initiatorHome != null)
                {
                    variables.put(WorkflowConstants.PROP_INITIATOR_HOME, nodeConverter.convertNode(initiatorHome));
                }
            }

bprado
Champ in-the-making
Champ in-the-making
Thank you Frederik … I was trying to find some reference on how to set the initiator for a couple of days. I'm new to Alfresco, Activiti, Java and Javascript (go figure what I'm doing here), so I'm probably doing something wrong.

Created a ExecutionListener on workflow-start with the code you suggested. Here is my definition:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="fcteste1" name="fcteste1" isExecutable="true">
    <extensionElements>
      <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
        <activiti:field name="script">
          <activiti:string>NodeRef initiator = getPersonNodeRef(currentUserName);
            if (initiator != null)
            {
                variables.put(WorkflowConstants.PROP_INITIATOR, nodeConverter.convertNode(initiator));
                // Also add the initiator home reference, if one exists
                NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
                if (initiatorHome != null)
                {
                    variables.put(WorkflowConstants.PROP_INITIATOR_HOME, nodeConverter.convertNode(initiatorHome));
                }
            }</activiti:string>
        </activiti:field>
      </activiti:executionListener>
    </extensionElements>
    <startEvent id="timerstartevent1" name="Timer start" activiti:initiator="bruno">
      <timerEventDefinition>
        <timeCycle>R5/PT1M</timeCycle>
      </timerEventDefinition>
    </startEvent>
    <userTask id="usertask1" name="Timer Task" activiti:assignee="bruno" activiti:candidateUsers="bruno,teste" activiti:formKey="wf:adhocTask">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>logger.log("Timed task created as expected");</activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow1" sourceRef="timerstartevent1" targetRef="usertask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_fcteste1">
    <bpmndi:BPMNPlane bpmnElement="fcteste1" id="BPMNPlane_fcteste1">
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="340.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="timerstartevent1" id="BPMNShape_timerstartevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="100.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="180.0" y="270.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="135.0" y="297.0"></omgdi:waypoint>
        <omgdi:waypoint x="180.0" y="297.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="285.0" y="297.0"></omgdi:waypoint>
        <omgdi:waypoint x="340.0" y="297.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>


When the TimerEvent fires, I get the following error in logs:



Mar 08, 2013 1:26:46 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener doesn't implement interface org.activiti.engine.delegate.ExecutionListener nor interface org.activiti.engine.delegate.JavaDelegate
        at org.activiti.engine.impl.bpmn.helper.ClassDelegate.getExecutionListenerInstance(ClassDelegate.java:82)
        at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:68)
        at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:42)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.start(ExecutionEntity.java:335)
        at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:72)
        at org.activiti.engine.impl.jobexecutor.TimerStartEventJobHandler.execute(TimerStartEventJobHandler.java:38)
        at org.activiti.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:78)
        at org.activiti.engine.impl.persistence.entity.TimerEntity.execute(TimerEntity.java:62)
        at org.activiti.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:67)
        at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)

frederikherema1
Star Contributor
Star Contributor
Don't use org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener, use org.alfresco.repo.workflow.activiti.tasklistener.ScriptExecutionListener.. There is a difference between execution-listeners and task-listeners.

bprado
Champ in-the-making
Champ in-the-making
Thank you, very much, for your patience frederik

Using org.alfresco.repo.workflow.activiti.tasklistener.ScriptExecutionListener I got an error.


Exception in thread "pool-1-thread-18" org.activiti.engine.ActivitiException: couldn't instantiate class org.alfresco.repo.workflow.activiti.tasklistener.ScriptExecutionListener
        at org.activiti.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:131)
        at org.activiti.engine.impl.bpmn.helper.ClassDelegate.instantiateDelegate(ClassDelegate.java:162)
        at org.activiti.engine.impl.bpmn.helper.ClassDelegate.getExecutionListenerInstance(ClassDelegate.java:76)
        at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:68)
        at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:42)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.start(ExecutionEntity.java:335)
        at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:72)
        at org.activiti.engine.impl.jobexecutor.TimerStartEventJobHandler.execute(TimerStartEventJobHandler.java:38)
        at org.activiti.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:78)
        at org.activiti.engine.impl.persistence.entity.TimerEntity.execute(TimerEntity.java:62)
        at org.activiti.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:67)
        at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: org.activiti.engine.ActivitiClassLoadingException: Class not found: org.alfresco.repo.workflow.activiti.tasklistener.ScriptExecutionListener
        at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:81)
        at org.activiti.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:128)
        … 23 more
Caused by: java.lang.ClassNotFoundException: org.alfresco.repo.workflow.activiti.tasklistener.ScriptExecutionListener
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:62)
        … 24 more


Then I searched my folders for ScriptExecutionListener using grep and found  org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener. After adjusting my definitions, I got the following error:


Mar 08, 2013 2:44:53 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.alfresco.scripts.ScriptException: 020812277 Failed to execute supplied script: missing ; before statement (AlfrescoJS#2)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeString(RhinoScriptProcessor.java:278)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeString(ScriptServiceImpl.java:286)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScriptString(ScriptServiceImpl.java:193)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScriptString(ScriptServiceImpl.java:183)
        at sun.reflect.GeneratedMethodAccessor1736.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:159)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy255.executeScriptString(Unknown Source)
        at org.alfresco.repo.workflow.activiti.script.ActivitiScriptBase.executeScript(ActivitiScriptBase.java:104)
        at org.alfresco.repo.workflow.activiti.script.ActivitiScriptBase$1.doWork(ActivitiScriptBase.java:88)
        at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:529)
        at org.alfresco.repo.workflow.activiti.script.ActivitiScriptBase.executeScriptAsUser(ActivitiScriptBase.java:84)
        at org.alfresco.repo.workflow.activiti.script.ActivitiScriptBase.executeScript(ActivitiScriptBase.java:76)
        at org.alfresco.repo.workflow.activiti.script.DelegateExecutionScriptBase.runScript(DelegateExecutionScriptBase.java:70)
        at org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener.notify(ScriptExecutionListener.java:52)
        at org.activiti.engine.impl.delegate.ExecutionListenerInvocation.invoke(ExecutionListenerInvocation.java:34)
        at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
        at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
        at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:70)
        at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:42)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.start(ExecutionEntity.java:335)
        at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:72)
        at org.activiti.engine.impl.jobexecutor.TimerStartEventJobHandler.execute(TimerStartEventJobHandler.java:38)
        at org.activiti.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:78)
        at org.activiti.engine.impl.persistence.entity.TimerEntity.execute(TimerEntity.java:62)
        at org.activiti.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:67)
        at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: org.mozilla.javascript.EvaluatorException: missing ; before statement (AlfrescoJS#2)
        at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
        at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:96)
        at org.mozilla.javascript.Parser.addError(Parser.java:140)
        at org.mozilla.javascript.Parser.reportError(Parser.java:154)
        at org.mozilla.javascript.Parser.statementHelper(Parser.java:1225)
        at org.mozilla.javascript.Parser.statement(Parser.java:655)
        at org.mozilla.javascript.Parser.parse(Parser.java:377)
        at org.mozilla.javascript.Parser.parse(Parser.java:315)
        at org.mozilla.javascript.Context.compileImpl(Context.java:2320)
        at org.mozilla.javascript.Context.compileString(Context.java:1348)
        at org.mozilla.javascript.Context.compileString(Context.java:1337)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeString(RhinoScriptProcessor.java:268)
        … 50 more

Exception in thread "pool-1-thread-24" org.alfresco.scripts.ScriptException: 020812277 Failed to execute supplied script: missing ; before statement (AlfrescoJS#2)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeString(RhinoScriptProcessor.java:278)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeString(ScriptServiceImpl.java:286)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScriptString(ScriptServiceImpl.java:193)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScriptString(ScriptServiceImpl.java:183)
        at sun.reflect.GeneratedMethodAccessor1736.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:159)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy255.executeScriptString(Unknown Source)
        at org.alfresco.repo.workflow.activiti.script.ActivitiScriptBase.executeScript(ActivitiScriptBase.java:104)
        at org.alfresco.repo.workflow.activiti.script.ActivitiScriptBase$1.doWork(ActivitiScriptBase.java:88)
        at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:529)
        at org.alfresco.repo.workflow.activiti.script.ActivitiScriptBase.executeScriptAsUser(ActivitiScriptBase.java:84)
        at org.alfresco.repo.workflow.activiti.script.ActivitiScriptBase.executeScript(ActivitiScriptBase.java:76)
        at org.alfresco.repo.workflow.activiti.script.DelegateExecutionScriptBase.runScript(DelegateExecutionScriptBase.java:70)
        at org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener.notify(ScriptExecutionListener.java:52)
        at org.activiti.engine.impl.delegate.ExecutionListenerInvocation.invoke(ExecutionListenerInvocation.java:34)
        at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
        at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
        at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:70)
        at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:42)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.start(ExecutionEntity.java:335)
        at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:72)
        at org.activiti.engine.impl.jobexecutor.TimerStartEventJobHandler.execute(TimerStartEventJobHandler.java:38)
        at org.activiti.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:78)
        at org.activiti.engine.impl.persistence.entity.TimerEntity.execute(TimerEntity.java:62)
        at org.activiti.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:67)
        at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: org.mozilla.javascript.EvaluatorException: missing ; before statement (AlfrescoJS#2)
        at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
        at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:96)
        at org.mozilla.javascript.Parser.addError(Parser.java:140)
        at org.mozilla.javascript.Parser.reportError(Parser.java:154)
        at org.mozilla.javascript.Parser.statementHelper(Parser.java:1225)
        at org.mozilla.javascript.Parser.statement(Parser.java:655)
        at org.mozilla.javascript.Parser.parse(Parser.java:377)
        at org.mozilla.javascript.Parser.parse(Parser.java:315)
        at org.mozilla.javascript.Context.compileImpl(Context.java:2320)
        at org.mozilla.javascript.Context.compileString(Context.java:1348)
        at org.mozilla.javascript.Context.compileString(Context.java:1337)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeString(RhinoScriptProcessor.java:268)
        … 50 more


And here is the adjusted workflow:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="fcteste1" name="fcteste1" isExecutable="true">
    <extensionElements>
      <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
        <activiti:field name="script">
          <activiti:string>
            NodeRef initiator = getPersonNodeRef(currentUserName);
            if (initiator != null)
            {
                variables.put(WorkflowConstants.PROP_INITIATOR, nodeConverter.convertNode(initiator));
                // Also add the initiator home reference, if one exists
                NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
                if (initiatorHome != null)
                {
                    variables.put(WorkflowConstants.PROP_INITIATOR_HOME, nodeConverter.convertNode(initiatorHome));
                }
            }
            </activiti:string>
        </activiti:field>
      </activiti:executionListener>
    </extensionElements>
    <startEvent id="timerstartevent1" name="Timer start" activiti:initiator="bruno">
      <timerEventDefinition>
        <timeCycle>R5/PT1M</timeCycle>
      </timerEventDefinition>
    </startEvent>
    <userTask id="usertask1" name="Timer Task" activiti:assignee="bruno" activiti:candidateUsers="bruno,teste" activiti:formKey="wf:adhocTask">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>logger.log("Timed task created as expected");</activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow1" sourceRef="timerstartevent1" targetRef="usertask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_fcteste1">
    <bpmndi:BPMNPlane bpmnElement="fcteste1" id="BPMNPlane_fcteste1">
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="340.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="timerstartevent1" id="BPMNShape_timerstartevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="100.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="180.0" y="270.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="135.0" y="297.0"></omgdi:waypoint>
        <omgdi:waypoint x="180.0" y="297.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="285.0" y="297.0"></omgdi:waypoint>
        <omgdi:waypoint x="340.0" y="297.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>

frederikherema1
Star Contributor
Star Contributor
I provided you the JAVA code as it's used by alfresco, you'll have to translate it to JS yourself and apply a similar pattern OR add a ServiceTask, backed by a JavaDelegate with that java-code in it.

bprado
Champ in-the-making
Champ in-the-making
Thank you again for pointing me in the right direction. I had just noticed that it's a JAVA code and not JS Smiley Happy
I'll do some research and, as soon as I have it figured out, I'll  post back here.

bprado
Champ in-the-making
Champ in-the-making
Couldn't find a way to do it using WebScript. Do you have a document/guide to get me started?

frederikherema1
Star Contributor
Star Contributor
To do what using a web script?

bprado
Champ in-the-making
Champ in-the-making
Set the initiator-variable, using a ExecutionListenter on workflow-start (using JavaScript instead of Java)