cancel
Showing results for 
Search instead for 
Did you mean: 

switch to admin user during a workflow dinamically

mabu_alf
Champ in-the-making
Champ in-the-making
Hi. I'd like to understand if it's possible to switch to admin user during a workflow dinamically.
I'm sure that admin can perform moving or deleting action over all space.
I'd like to define something like:

    step 1: user A start a workflow in his home space;
    step 2: admin user (inside the workflow) moves the document to a specific space where the user B can access;
    step 3: user B perform a task;
    step 4: admin moves the document to original position.
I try to implement the movement but I have some problem to store the initial position of the document(package). This is the code:


<task-node name="tsk1">
      <task name="wf:task1" swimlane="initiator" />
      <transition name="go" to="tsk2">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            var origin = bpm_context.name;
            var dest = companyhome.childByNamePath("Intranet/SharedSpace/");
            for (var i = 0; i &lt; bpm_package.children.length; i++)
            {
               bpm_package.children[i].move(dest);
            }
         </script>
      </action>
     </transition>
   </task-node>  
  
   <task-node name="tsk2">
     <task name="wf:task2" swimlane="assignee"/>
     <transition name="finish" to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i &lt; bpm_package.children.length; i++)
               {
                  bpm_package.children[i].move(origin);
               }
            </script>
         </action>
     </transition>
   </task-node>

and this is the error (initial part):

17:12:46,556 ERROR [graph.def.GraphElement] action threw exception: Failed to execute supplied script: ReferenceError: "origin" is not defined. (AlfrescoScript#1)
org.alfresco.service.cmr.repository.ScriptException: Failed to execute supplied script: ReferenceError: "origin" is not defined. (AlfrescoScript#1)
   at org.alfresco.repo.jscript.RhinoScriptService.executeScriptString(RhinoScriptService.java:235)
   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:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
   at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:116)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:204)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
   at $Proxy55.executeScriptString(Unknown Source)
   at org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript.executeScript(AlfrescoJavaScript.java:157)
"origin" is not global?
Can anybody help me?

Thanks for any advice
2 REPLIES 2

davidc
Star Contributor
Star Contributor
"origin" is not global?

You need to pass your local script variable to the containing script context…

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

http://wiki.alfresco.com/wiki/WorkflowAdministration#Actions_.26_Scripting

mabu_alf
Champ in-the-making
Champ in-the-making
You need to pass your local script variable to the containing script context…

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

http://wiki.alfresco.com/wiki/WorkflowAdministration#Actions_.26_Scripting

Thank for this suggest.

I tried to adjust the code, but I don't know so much about Java Script, so I must try many times to make it work.
First test:


<task-node name="tsk1">
      <task name="wf:task1" swimlane="initiator" />
      <transition name="go" to="tsk2">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
         <expression>
            var origin = bpm_context.name;
            var dest = companyhome.childByNamePath("Intranet/SharedSpace/");
            for (var i = 0; i &lt; bpm_package.children.length; i++)
            {
               bpm_package.children[i].move(dest);
            }
         </expression>
         <variable name="origin" access="write"/>
         </script>
      </action>
     </transition>
   </task-node>  

   <task-node name="tsk2">
     <task name="wf:task2" swimlane="assignee"/>
     <transition name="finish" to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
            <expression>
               for (var i = 0; i &lt; bpm_package.children.length; i++)
               {
                 bpm_package.children[i].move(origin);
               }
            </expression>
            </script>
         </action>
     </transition>
   </task-node>

and this is the error (initial part):

14:15:03,542 ERROR [graph.def.GraphElement] action threw exception: Failed to execute supplied script: Can't find method org.alfresco.repo.jscript.Node.move(boolean). (AlfrescoScript#1)
org.alfresco.service.cmr.repository.ScriptException: Failed to execute supplied script: Can't find method org.alfresco.repo.jscript.Node.move(boolean). (AlfrescoScript#1)
   at org.alfresco.repo.jscript.RhinoScriptService.executeScriptString(RhinoScriptService.java:235)
Second test:


<task-node name="tsk1">
      <task name="wf:task1" swimlane="initiator" />
      <transition name="go" to="tsk2">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
         <expression>
            var origin = bpm_context.name;
            var dest = companyhome.childByNamePath("Intranet/SharedSpace/");
            for (var i = 0; i &lt; bpm_package.children.length; i++)
            {
               bpm_package.children[i].move(dest);
            }
         </expression>
         <variable name="origin" access="write"/>
         </script>
      </action>
     </transition>
   </task-node>  

   <task-node name="tsk2">
     <task name="wf:task2" swimlane="assignee"/>
     <transition name="finish" to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
            <expression>
               for (var i = 0; i &lt; bpm_package.children.length; i++)
               {
                 bpm_package.children[i].move(origin);
               }
            </expression>
            <variable name="origin" access="read"/>
            </script>
         </action>
     </transition>
   </task-node>

and this is the error (initial part):

14:30:10,891 ERROR [graph.def.GraphElement] action threw exception: Failed to execute supplied script: ReferenceError: "bpm_package" is not defined. (AlfrescoScript#1)
org.alfresco.service.cmr.repository.ScriptException: Failed to execute supplied script: ReferenceError: "bpm_package" is not defined. (AlfrescoScript#1)
   at org.alfresco.repo.jscript.RhinoScriptService.executeScriptString(RhinoScriptService.java:235)
Where is, where are the mistakes?

Can you send me a exemplifying sample code please?

Thank you so much.