Page 1 of 1

runProcessDefinition - From Script.

PostPosted:Fri Aug 05, 2011 8:43 pm
by UMI_IT
We've created a workflow, and can manually invoke it through the GUI. We've also successfully fired an event upon upload to have some action occur (rename, move etc.) Where we are falling down is causing that workflow to fire from the script. We've been trying to fire the workflow from the Administration -> Scripts window and can't get it to fire.
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.base.*;
import com.openkm.api.*;
import com.openkm.module.*;
import com.openkm.bean.workflow.*;
import com.openkm.bean.form.*;
import com.openkm.module.direct.*;
import com.openkm.module.WorkflowModule.*;

String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
WorkflowModule wm = ModuleManager.getWorkflowModule();
ProcessDefinition pd = wm.getProcessDefinition(token, 13);
ProcessInstance pi;
String myUUID;
pi=wm.runProcessDefinition(token,14,myUUID,wm.getProcessDefinitionForms(token,14));
print(pi);
This is the error:
Code: Select all
Sourced file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : Error in method invocation: Method runProcessDefinition( java.lang.String, int, null, java.util.HashMap ) not found in class'com.openkm.module.direct.DirectWorkflowModule' : at Line: 18 : in file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : wm .runProcessDefinition ( token , 14 , myUUID , wm .getProcessDefinitionForms ( token , 14 ) ) 
No matter what is included the error
Method runProcessDefinition not found in class..
.

OpenKM Version: 5.1.7 (build: 7085)

Any pointers?

Re: runProcessDefinition - From Script.

PostPosted:Mon Aug 08, 2011 11:43 am
by jllort
Invocation might be something like
Code: Select all
OKMWorkflow.getInstance().runProcessDefinition(null, new Double(id).longValue(), UUID, formElementList);

Re: runProcessDefinition - From Script.

PostPosted:Mon Aug 08, 2011 11:59 am
by UMI_IT
Same error as before. We're trying to fire off a workflow when something is uploaded. The wiki didn't have any examples of such (unless they are behind the locked section.) Google also wasn't any help "openkm runprocessdefinition" was the query.

Re: runProcessDefinition - From Script.

PostPosted:Tue Aug 09, 2011 7:46 am
by jllort
I suggest try with core extension http://wiki.openkm.com/index.php/Core_extensions you could debug with eclipse and then you'll know better whats happening, one of the problem of the scripting is debug.

You've got exactly the same error than other code ? Post here your code and workflow test in order could testing it ( some zip )

Re: runProcessDefinition - From Script.

PostPosted:Tue Aug 09, 2011 1:09 pm
by UMI_IT
This is within OpenKM itself, and not eclipse. I'm trying to run this from within Administration->Scripts. The error I get is the same as before:
Code: Select all
Sourced file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : Error in method invocation: Method runProcessDefinition( java.lang.String, int, null, java.util.HashMap ) not found in class'com.openkm.module.direct.DirectWorkflowModule' : at Line: 18 : in file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : wm .runProcessDefinition ( token , 14 , myUUID , wm .getProcessDefinitionForms ( token , 14 ) ) 
Note the bit about runProcessDefintion not being found in any included file. The workflow simply sends an email, and works when invoked from the OpenKM web GUI.

If I do anything but do the runProcessDefinition, it works. For whatever reason, OpenKM can't find runProcessDefintion. Is there a working example around that calls a workflow from a script?

Re: runProcessDefinition - From Script.

PostPosted:Thu Aug 11, 2011 6:49 am
by jllort
We've not any example, because none of our customers has need it ( they use profile ). post here the workflow and the script code and will test on some of our OpenKM testing servers.

Re: runProcessDefinition - From Script.

PostPosted:Thu Aug 11, 2011 3:28 pm
by UMI_IT
We have been using whats up to to try and run this. The script itself does nothing really, we just want to find a way to trigger an even on a document entry into a openkm folder.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>

<process-definition  xmlns="urn:jbpm.org:jpdl-3.2"  name="UserInput">
  <start-state name="start">
    <transition to="PlaceOrder" name="trPlaceOrder"></transition>
  </start-state>
  <task-node name="PlaceOrder">
    <task name="MyTask">
      <assignment actor-id="okmAdmin"></assignment>
      <controller></controller>
    </task>
    <transition to="CheckAvailability"></transition>
  </task-node>
  <decision name="CheckAvailability" expression="#{(amount.value>100)?'trNotAvailable':'trAvailable'}">
    <transition to="end" name="trAvailable"></transition>
    <transition to="sendMail" name="trNotAvailable"></transition>
  </decision>
  <mail-node name="sendMail" to="it@uppermohawkinc.com">
    <subject>Out of stock.</subject>
    <text>Order requires more Inventory.</text>
    <transition to="end"></transition>
  </mail-node>
  <end-state name="end"></end-state>
</process-definition>

Re: runProcessDefinition - From Script.

PostPosted:Fri Aug 12, 2011 7:28 am
by jllort
I've been testing it and seems is running
Code: Select all
import java.util.List;
import java.util.ArrayList;
import com.openkm.api.OKMWorkflow;

List formElements = new ArrayList();
String UUID = "bd62b51c-3102-48c7-bf99-7439b53d4c9a";
int id = 20622;
OKMWorkflow.getInstance().runProcessDefinition(null, new Double(id).longValue(), UUID, formElements);
Where UUID is some document UUID and id is process id ( you can look at administrator workflow ).

Re: runProcessDefinition - From Script.

PostPosted:Fri Aug 12, 2011 11:19 am
by UMI_IT
That was exactly it! Thanks for your assistance. For others who may want to follow the same path, here is the full script (added to the folder):
Code: Select all
import java.util.List;
import java.util.ArrayList;
import com.openkm.api.OKMWorkflow;

if (eventType.equals("CREATE_DOCUMENT")) {
List formElements = new ArrayList();
String UUID = "8e751d42-7365-405b-85fe-3dcb8c296e7c";
int id = 15;
OKMWorkflow.getInstance().runProcessDefinition(null, new Double(id).longValue(), UUID, formElements);
}
As previously mentioned, the UUID is just the UUID of the folder, id is the process id.

Re: runProcessDefinition - From Script.

PostPosted:Fri Aug 12, 2011 2:45 pm
by jllort
You can get the UUID of the document or folder from execution script ( obviously not executing on administration, but when is fired by event can easilly get it ).
Code: Select all
String UUID = eventNode.getUUID();
or the parent ( in your example you used fixed parent UUID )
Code: Select all
String parentUUID = eventNode.getParent().getUUID();

Re: runProcessDefinition - From Script.

PostPosted:Fri Aug 12, 2011 2:56 pm
by UMI_IT
Thanks for the tip! We've been playing a lot with the scripting, and the only thing we ran into was the automatic firing of the work flow (which many other DMS have also.) OpenKM has a lot more going for it than other DMS. Getting automatic workflows (upon document upload) was a requirement, so now that its working, tick that off the list :-D

Re: runProcessDefinition - From Script.

PostPosted:Fri Aug 19, 2011 7:15 pm
by pavila
If you want to launch a workflow on document upload you can also use the user profile. In the user profile (see it in administration), you can select a workflow to be launched when an user upload a document.

Re: runProcessDefinition - From Script.

PostPosted:Fri Aug 19, 2011 7:41 pm
by UMI_IT
We wanted to be able to do this per folder, not per profile. As we see it, there will be only a few profiles. Users will have access to several folders, and each may have its own workflow (invoice, expense report, etc). We don't want to fire necessary workflows when the user uploads something and we don't want to impose that the user changes their profile to upload a file. Since it seemed possible (and it is) to do so per folder, that's the route we are going to take. Many DMS systems allow setting workflow auto-execution per folder. OpenKM is a wonderful piece of software and it works well. The only thing missing that we have a business case for out of the box is setting a workflow per folder (not all need it, but there are a few that do.) Now that we have it, we can begin planning to use this package.

Re: runProcessDefinition - From Script.

PostPosted:Wed Aug 24, 2011 8:46 am
by pavila
I have created an issue to handle this improvement (http://issues.openkm.com/view.php?id=1749). I think is an interesting one and will be included in OpenKM in a near future. For now, as you already have done, this need to be done with scripting or with Core Extensions.