cancel
Showing results for 
Search instead for 
Did you mean: 

Advanced Workflow initiated via a Rule

nowhere
Champ in-the-making
Champ in-the-making
Hi all,
I have a very stupid question…can I initiate an advanced workflow by a rule in web gui?
I have read there is a "start-workflow" action, but I found pour documentation about it. Can someone tell me where read more?
Thanks!
14 REPLIES 14

riogrande
Champ in-the-making
Champ in-the-making
I'm interested in that too. Do you find a way to do that ?

cytrix
Champ in-the-making
Champ in-the-making
You could execute a workflow with the "Execute script" action.
Scripts are in the "Company Home > Data Dictionary > Scripts" repository.

The script execute the workflow automatically .

Script example :

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$alwf:my_workflow";
workflow.execute(document);

riogrande
Champ in-the-making
Champ in-the-making
Thanks, but than, how can I use "document" in the workflow ?
for example I would like to check the status of the file document.properties["af:status"], but he says "document is not define".

chicco0386
Champ on-the-rise
Champ on-the-rise
Thanks, but than, how can I use "document" in the workflow ?
for example I would like to check the status of the file document.properties["af:status"], but he says "document is not define".

Same problem…
I've error when I use document.name…
<node name="hello">
   <transition name="" to="end1">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            <expression>
               logger.log(document.name);
            </expression>
         </script>
      </action>
   </transition>
</node>

Have same solution?

riogrande
Champ in-the-making
Champ in-the-making
It seems that we have to use something like "bpm_package.children[0].name" (children[0] for the first item, if you have more attached files in your workflow, you have to use a "for" loop). But I have the same problem "bpm_package is not defined"…

cytrix
Champ in-the-making
Champ in-the-making
Perhaps by creating a docName variable in your script ?

exec_workflow_action.js :

var workflow = actions.create("start-workflow");
workflow.parameters["bpm:docName"] = document.name;
workflow.parameters.workflowName = "jbpm$alwf:my_workflow";
workflow.execute(document);

In the processdefinition file :

<node name="hello">
   <transition name="" to="end1">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            <expression>
                  logger.log(bpm.docName);
            </expression>
         </script>
      </action>
   </transition>
</node>

cytrix
Champ in-the-making
Champ in-the-making
It seems that we have to use something like "bpm_package.children[0].name" (children[0] for the first item, if you have more attached files in your workflow, you have to use a "for" loop). But I have the same problem "bpm_package is not defined"…

Yes, i think it works Smiley Happy .

Try this to use bpm_package (it's works for me) :

<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
              <script>
               <variable name="bpm_package" access="read" />
               <variable name="companyhome" access="read" />
               <expression>
                  for (var i=0; i &lt; bpm_package.children.length; i++) {
                     var dest = companyhome.childByNamePath("documents validés");
                     bpm_package.children[i].move(dest);
                  }
               </expression>
              </script>
           </action>

riogrande
Champ in-the-making
Champ in-the-making
yes I find it at the moment ! (here)

But I have an other problem now !
"org.alfresco.service.cmr.workflow.WorkflowException: Script expression has not been provided"

my js script


   var workflow = actions.create("start-workflow");
   workflow.parameters.workflowName = "jbpm$af:workflowTest";
   workflow.execute(document);

and my workflow

<?xml version="1.0" encoding="UTF-8"?>

<process-definition  xmlns="urn:jbpm.org:jpdl-3.1"  name="af:workflowTest">

   <start-state name="start">
      <transition to="Message"></transition>
   </start-state>

   <node name="Message">
      <transition to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
            <runas>admin</runas>
            <variable name="bpm_package" access="read" />
            if(bpm_package.children.length != 0){
               if(bpm_package.children[0].properties["af:status"] == "Pending"){
                  logger.log("####### Status : " + bpm_package.children[0].properties["af:status"] + " need validation !");
               }else{
                  logger.log("======= Status : " + bpm_package.children[0].properties["af:status"] + " didn't need validation.");
               }
            }else{
               logger.log("No file attached !");
            }
            </script>
         </action>   
      </transition>
   </node>

   <end-state name="end"></end-state>

</process-definition>

the full log
11:03:16,000 ERROR [org.jbpm.graph.def.GraphElement] action threw exception: Script expression has not been provided
org.alfresco.service.cmr.workflow.WorkflowException: Script expression has not been provided
   at org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript.execute(AlfrescoJavaScript.java:123)
   at org.jbpm.graph.def.Action.execute(Action.java:122)
   at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:264)
   at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:220)
   at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:190)
   at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:174)
   at org.jbpm.graph.def.Transition.take(Transition.java:138)
   at org.jbpm.graph.def.Node.leave(Node.java:394)
   at org.jbpm.graph.def.Node.leave(Node.java:358)
   at org.jbpm.graph.def.Node.execute(Node.java:350)
   at org.jbpm.graph.def.Node.enter(Node.java:319)
   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.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:157)
   at org.jbpm.graph.def.Node$$EnhancerByCGLIB$$69e64b0d.enter(<generated>)
   at org.jbpm.graph.def.Transition.take(Transition.java:151)
   at org.jbpm.graph.def.Node.leave(Node.java:394)
   at org.jbpm.graph.node.StartState.leave(StartState.java:70)
   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.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:157)
   at org.jbpm.graph.def.Node$$EnhancerByCGLIB$$69e64b0d.leave(<generated>)
   at org.jbpm.graph.exe.Token.signal(Token.java:195)
   at org.jbpm.graph.exe.Token.signal(Token.java:140)
   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.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:157)
   at org.jbpm.graph.exe.Token$$EnhancerByCGLIB$$1674f1a1.signal(<generated>)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine$18.doInJbpm(JBPMEngine.java:976)
   at org.springmodules.workflow.jbpm31.JbpmTemplate$1.doInHibernate(JbpmTemplate.java:87)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:338)
   at org.springmodules.workflow.jbpm31.JbpmTemplate.execute(JbpmTemplate.java:80)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.signal(JBPMEngine.java:965)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.signal(WorkflowServiceImpl.java:417)
   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:296)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:301)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:229)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy51.signal(Unknown Source)
   at org.alfresco.repo.workflow.WorkflowInterpreter.executeCommand(WorkflowInterpreter.java:954)
   at org.alfresco.repo.admin.BaseInterpreter$1$1.execute(BaseInterpreter.java:163)
   at org.alfresco.repo.admin.BaseInterpreter$1$1.execute(BaseInterpreter.java:161)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:320)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:227)
   at org.alfresco.repo.admin.BaseInterpreter$1.doWork(BaseInterpreter.java:166)
   at org.alfresco.repo.admin.BaseInterpreter$1.doWork(BaseInterpreter.java:157)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:437)
   at org.alfresco.repo.admin.BaseInterpreter.interpretCommand(BaseInterpreter.java:155)
   at org.alfresco.web.bean.workflow.WorkflowConsoleBean.interpretCommand(WorkflowConsoleBean.java:196)
   at org.alfresco.web.bean.workflow.WorkflowConsoleBean.submitCommand(WorkflowConsoleBean.java:161)
   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.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
   at javax.faces.component.UICommand.broadcast(UICommand.java:109)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
   at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
   at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.AdminAuthenticationFilter.doFilter(AdminAuthenticationFilter.java:80)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)

cytrix
Champ in-the-making
Champ in-the-making
Try add <expression> after the variable access definition :

   <node name="Message">
      <transition to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
            <runas>admin</runas>
            <variable name="bpm_package" access="read" />
            <expression>
                                   if(bpm_package.children.length != 0){
               if(bpm_package.children[0].properties["af:status"] == "Pending"){
                  logger.log("####### Status : " + bpm_package.children[0].properties["af:status"] + " need validation !");
               }else{
                  logger.log("======= Status : " + bpm_package.children[0].properties["af:status"] + " didn't need validation.");
               }
            }else{
               logger.log("No file attached !");
            }
                                </expression>
            </script>
         </action>   
      </transition>
   </node>