Free Source Code and Program Tips
Source code to start a JBPM process instance
Following is the sample code of how to start a JBPM process instance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | / ** * Start a process instance. * * @ Param name * Process name. * @ Param version * Version number, default is the latest version. * @ Param formID * Business-related form number ,optional field. * The meaning of the parameter is: after filling the form, the process uses the ID as the process instance variable. * It was Saved in the workflow system, so the form data can be obtained from business information with the ID. * @ Param actor * Sponsor of the process. * @ Return instance * ID No. + task instance ID (if any), the format 'ID No.-task instance ID'. * / public String startProcessInstance(String name, int version, String formID, String actor); jbpmContext = jbpmConfiguration.createJbpmContext(); try { ProcessDefinition def; if (version == 0) { def = jbpmContext.getGraphSession().findLatestProcessDefinition(name); } else { def = jbpmContext.getGraphSession().findProcessDefinition(name,version); } ProcessInstance instance = new ProcessInstance(def); TaskInstance taskInstance = instance.getTaskMgmtInstance().createStartTaskInstance(); if ((formID != null) && (!formID.equals(""))) instance.getContextInstance().setVariable( name + "-" + version + "-"+ instance.getId()+ "-Form", formID); jbpmContext.save(instance); String rtn = String.valueOf(instance.getId()); //if any task instance if (taskInstance != null){ taskInstance.setActorId(actor); rtn += "-"+ String.valueOf(taskInstance.getId()); }else{ instance.getRootToken().signal(); } return rtn; } catch (Exception e) { e.printStackTrace(); log.error(e.getMessage()); } finally { jbpmContext.close(); } return ""; } |
| Print article | This entry was posted by support on January 1, 2009 at 8:37 pm, and is filed under Java. Follow any responses to this post through RSS 2.0. You can skip to the end and leave a response. Pinging is currently not allowed. |