• runProcessDefinition - From Script.

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #11748  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?
 #11768  by jllort
 
Invocation might be something like
Code: Select all
OKMWorkflow.getInstance().runProcessDefinition(null, new Double(id).longValue(), UUID, formElementList);
 #11770  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.
 #11782  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 )
 #11788  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?
 #11799  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.
 #11805  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>
 #11811  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 ).
 #11813  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.
 #11814  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();
 #11815  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
 #11855  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.
 #11857  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.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.