Following is the sample code of how to start a JBPM process instance.
/ ** * 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 ""; }
Permalink: Code Library - Source code to start a JBPM process instance
Subcribe the update with Google Reader.
RSS feed for comments on this post
Leave a reply