cancel
Showing results for 
Search instead for 
Did you mean: 

How to modify the content of bpm_package and other questions

riogrande
Champ in-the-making
Champ in-the-making
Hi all,

I'm working on a Workflow and I have some questions.
My workflow looks like this (in fact it's a real basic one) :

[img]http://img194.imageshack.us/img194/9379/workflow.png[/img]

So, the file come in, if the custom status is "Pending" the file enter in the validation process, otherwise it goes directly to the end (that works fine).
Then, a validator has the possibility to modify and approve the document or reject it so that the initiator has to make the corrections.
I would like to give to the Validator the possibility to valid the file directly even though the status is "Pending". The workflow has to set the file to "In" before the end (in the "IsValid" node).
Another possibility: the initiator can put directly the status to "In" to avoid the validation. 

Here is the code :

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

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

   <swimlane name="initiator" />

   <swimlane name="validator">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <pooledactors>#{people.getGroup('GROUP_Administrator')}</pooledactors>
      </assignment>
   </swimlane>
   
   
   <start-state name="start">
      <task name="bpm:startTask" swimlane="initiator" />
      <transition to="IsPending">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="bpm_package" access="read" />
               <variable name="statusValue" access="read,write"/>
               <expression>
                  statusValue = bpm_package.children[0].properties["af:status"];
               </expression>
            </script>
         </action>
      </transition>
   </start-state>


   <decision name="IsPending">      
      <transition to="end" name="NoValidationNeeded">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="statusValue" access="read" />
               <expression>
                  logger.log("No validation needed, because status is set to '" + statusValue + "' need 'Pending'");
               </expression>
            </script>
         </action>         
      </transition>
      <transition to="Validation" name="ValidationNeeded">
         <condition>#{statusValue == "Pending"}</condition>   
      </transition>
   </decision>


   <task-node name="Validation">
      <task name="afwf:validation" swimlane="validator" />
      <transition to="IsValid" name="approved"></transition>
      <transition to="Correction" name="reject"></transition>
   </task-node>


   <task-node name="Correction">
      <task name="afwf:correction" swimlane="initiator" />
      <transition to="IsPending" name="done">   
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="bpm_package" access="read" />
               <variable name="statusValue" access="read,write"/>
               <expression>
                  statusValue = bpm_package.children[0].properties["af:status"];
               </expression>
            </script>
         </action>      
      </transition>
   </task-node>


   <node name="IsValid">
      <transition to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <runas>admin</runas>
               <variable name="bpm_package" access="read" />
               <expression>
               logger.log("Is in IsValid");
                  if(bpm_package.children[0].properties["af:status"] == "Pending"){
                     bpm_package.children[0].properties["af:status"] = "In";
                     logger.log("Status set to 'In'");
                  }
               </expression>
            </script>
         </action>   
      </transition>
   </node>


   <end-state name="end">
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <expression>
                  logger.log("End of the Physical Archive Validation !");
               </expression>
            </script>
         </action>
      </event>      
   </end-state>

</process-definition>


The workflow is launched by a .js file and it works very well.

Now I have 3 problems (I couldn't put the three in the title of the topic Smiley Happy )

1.- After the "Correction" task I made an update of the "statusValue" variable, but I doesn't work because it always returns to "Validation" (never get out of the loop).
2.- "bpm_package.children[0].properties["af:status"] = "In";" change noting and let the value to "Pending". Ok, you will say "easy, put read,write instead of read" but if I do so, I have this error :
19:46:30,375 ERROR [org.alfresco.web.ui.common.Utils] A system error happened during the operation: org.mozilla.javascript.Undefined cannot be cast to org.alfresco.repo.workflow.jbpm.JBPMNode
java.lang.ClassCastException: org.mozilla.javascript.Undefined cannot be cast to org.alfresco.repo.workflow.jbpm.JBPMNode
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowInstance(JBPMEngine.java:2775)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowPath(JBPMEngine.java:2673)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowTask(JBPMEngine.java:2830)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine$26.doInJbpm(JBPMEngine.java:1711)
   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.endTask(JBPMEngine.java:1670)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.endTask(WorkflowServiceImpl.java:544)
   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.endTask(Unknown Source)
   at org.alfresco.web.bean.workflow.ManageTaskDialog.transition(ManageTaskDialog.java:390)
   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.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)

3.- I would like to launch the workflow when a file is added, the problem is that it is launch just at the moment the file is created and doesn't give the time to edit the custom properties I defined. So although if you put "In" at the creation of the file, it will goes in the Validation part because the default value at the creation is "Pending" (I hope I make it understandable).

So sorry for my bad English, I hope that some of you have one or more answer to give to me.

Thanks  :mrgreen:
16 REPLIES 16

riogrande
Champ in-the-making
Champ in-the-making
thanks for your answer Smiley Happy

But what I didn't get is that in the details form each file you have that, there must be a way to get this values.
[img]http://www.digitalmindstudio.ch/~magicrio/alfresco/alfresco_workflow_counter.png[/img]

_sax
Champ in-the-making
Champ in-the-making
This is information that's a little deeper under the hood:
To access it you probably have to write a new java class, extending the actual workflowBean.
You then can incorporate this class into the details or list view of your document folders.

Here's how:
https://issues.alfresco.com/jira/browse/AR-892
http://www.wowww.nl/wordpress/?p=69
http://dev.alfresco.com/resource/docs/taglib/web-client/r/nodeWorkflowInfo.html

If you succeed in proceeding, I'm interested into how you've did it.

You're workflow rule then still would start more often, than you'd like it to do.
I don't know, how you could use a java bean function in a Java Script rule. :roll:

riogrande
Champ in-the-making
Champ in-the-making
Ok, my Java skills are very low, so I didn't know if I can do something with that Smiley Very Happy
At the moment, I think the easiest way for me is to add some "workflowLock" attribute to my file that I set to "true" when I get in and "false" when I get out of the workflow.
Not really elegant, but it should work.

riogrande
Champ in-the-making
Champ in-the-making
This is information that's a little deeper under the hood:
To access it you probably have to write a new java class, extending the actual workflowBean.
You then can incorporate this class into the details or list view of your document folders.

Here's how:
https://issues.alfresco.com/jira/browse/AR-892
http://www.wowww.nl/wordpress/?p=69
http://dev.alfresco.com/resource/docs/taglib/web-client/r/nodeWorkflowInfo.html

If you succeed in proceeding, I'm interested into how you've did it.

You're workflow rule then still would start more often, than you'd like it to do.
I don't know, how you could use a java bean function in a Java Script rule. :roll:

Array activeWorkflows :  Returns an array of all active workflows this node is involved in. If the node is not part of an active workflow, null is returned. Items in the returned array are of type JscriptWorkflowInstance.
Found here.
I was seeking in the workflow API… Obviously I miss that one. Thanks to MikeH.
Just note that (document.activeWorkflows == null) doesn't seems to work for tests, instead use (document.activeWorkflows.length == 0).

_sax
Champ in-the-making
Champ in-the-making
That is great, thank you!
Since we do not use 3.0 yet, I didn't study the according wiki page :roll:.

riogrande
Champ in-the-making
Champ in-the-making
I have a brand new question Smiley Very Happy

I have set a timer in one of my workflows. In the actions there are again my status change, but it don't take effect.


<timer name="afwf:pickupTimeOut" duedate="1 minutes" transition="reject">
   <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
      <runas>admin</runas>
      <script>
         <expression>
            bpm_package.children[0].properties["af:status"] = "Available";
            bpm_package.children[0].save();
            if (logger.isLoggingEnabled()) {
               logger.log("\nBorrowProcess : Time out, status set to back to 'Available'. This Workflow was launched by " + initiator.properties['firstName'] + " " + initiator.properties['lastName'] + ".");
            }
         </expression>
      </script>
   </action>
</timer>

So I though, it's maybe a rights problem, so I will do something like :

<type name="afwf:pickupTimeOut">
   <parent>bpm:workflowTask</parent>
   <overrides>
      <property name="bpm:packageItemActionGroup">
         <default>edit_package_item_actions</default>
      </property>
   </overrides>
</type>
But of course it doesn't work because a Timer is not a Task… So, any idea?

_sax
Champ in-the-making
Champ in-the-making
I suspect that your workflow doesn't run the timer script. You can prove that by adding a line like logger.log ("Timer reached");
in your script and reading the log.
Timing issues are sort of common, but they're mostly solved: http://forums.alfresco.com/en/viewtopic.php?f=34&t=13302&p=64991&hilit=timer#p44494