Activiti business key (businessKey), activiti

Source: Internet
Author: User
Tags key string

Activiti business key (businessKey), activiti

Q: How can I associate a business object with a corresponding process?

ProcessInstance has a method getBusinessKey () to get a businessKey.

The table act_ru_execution in the database corresponding to ProcessInstance has a field BUSINESS_KEY _, which corresponds to the businessKey in the class. This field is automatically set to unique when the table is created.

Solution:

1. Ensure that the process ID is consistent with the class name of the business object. For example, the process id is LeaveBill, and the class name of our business object is also created as LeaveBill.

2. Input businessKey and workflowService when obtaining the execution method of the business object when the process starts. startProcess (key, businessKey, vars); "+ objId

Public void startProcess (Long id) {// 1. Obtain the Business Object LeaveBill bill = this. get (id); if (bill! = Null) {// modify the Business Object Status bill. setState (1); // leave state 0 initial input, 1. start approval. 2. approve this. update (bill); // 2. add process variable (Map) Map <String, Object> vars = new HashMap <> (); vars. put ("inputUser", bill. getUser (). getName (); // Add a variable to describe the information of the Business Object String classType = bill. getClass (). getSimpleName (); vars. put ("classType", classType); vars. put ("objId", bill. getId (); // 3. start the process // obtain the process definition key String key = classType; // obtain the business key generation rule: className + ". "+ objId String businessKey = classType + ". "+ bill. getId (); this. workflowService. startProcess (key, businessKey, vars );}}

3. Use taskId to obtain the Business Object id as follows:

Public String getBusinessObjId (String taskId) {// 1 obtain the Task object task = taskService. createTaskQuery (). taskId (taskId ). singleResult (); // 2 obtain the process instance ProcessInstance pi = runtimeService through the task object. createProcessInstanceQuery (). processInstanceId (task. getProcessInstanceId ()). singleResult (); // 3 obtain the "Business key" String businessKey = pi through the process instance. getBusinessKey (); // 4 split the business key into an array of "Business Object Name" and "Business Object ID" // a = B LeaveBill.1 String objId = null; if (StringUtils. isNotBlank (businessKey) {objId = businessKey. split ("\\. ") [1];} return objId ;}

4. Obtain process instances and tasks based on the business key

ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey("LeaveBill.1").singleResult();Task task = taskService.createTaskQuery().processInstanceBusinessKey("LeaveBill.1").singleResult();

 

 

 

 

  


How can Activiti query the business objects associated with the process instance?

When you design your process xml, you have already set <activiti: formProperty id = "tablename" name = "table name" type = "string" required = "true" readable = "true" writable = "true"> </activiti: formProperty> put this item in xml. Then you can find this item and you will know which business table to query.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.