When starting a process, we save the process started by the current user as the process initiator (initiator, applicant, submitter)

The API does not specify how to store the process initiator information. So here’s a summary of what I’ve learned about saving process initiator information.

  • The practice in the Coffee Bunny blog -Activiti setup process initiate user information – Coffee Rabbit – HenryYan

    Note: If you do it purely as a blog, you canACT_HI_PROCINST 的 START_USER_ID_The field holds the value, but I don’t get it out. It’s always null.
  • As above, also used:identityService.setAuthenticatedUserId(userId);But there is also the start event in the process definitionstartEventSet the initial information in the start event. eg:
<startEvent id="startevent1" name="Start" activiti:initiator="applyUserId"/>
Copy the code

Note: Here applyUserId is stored in the process variable and its value isidentityService.setAuthenticatedUserId(userId)The saved userId. Because they are process variables, they can be obtained using the generic method of getting process variables.

  • As mentioned before using process variables (Map), there are many methods to start a process, and many overloads for the same method. Such as:
startProcessInstanceByKey(String processDefinitionKey, Map<String,Object> variables);
Copy the code

In addition to the key defined for the process, this startup also provides a map that maintains the variables of the process instance. You can store a lot of things in there, including initiator information. Such as:

// Set the applicant and save it in the process variable
Map<String ,Object > variables = new HashMap<>();
variables.put("applyUser"."kk");
Copy the code

As for getting the value of a process variable, here is an example:

Map<String,Object> vars = taskService.getVariables(task.getId());
for (String variableName : vars.keySet()) {
    String val = (String) vars.get(variableName);
    System.out.println(variableName + "=" +val);
}
Copy the code
  • Save in the business form. Maintain a redundant field in the business form to hold the initiator. That’s what the coffee Bunny Demo source code does.